Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Silently handle SQL-Exceptions on the server side

    Sometimes I get exceptions like
    Code:
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    on datasource add operations because of a duplicate primary key (generated on the server). This is by design and as these cases are rare, I’d like to handle the exception silently on the server rather than making sure this exception is not thrown at all.
    I’ve read http://www.smartclient.com/smartgwtee-latest/javadoc/com/smartgwt/client/docs/ErrorHandling.html but it seems like this is solely to handle errors from the client side.
    In a DMI, I tried wrapping
    Code:
    dsRequest.execute();
    into a try/catch block but it seems like the exception is thrown just after the DMI method is left.
    What other options are there to handle (SQL) exceptions on the server in a datasource operation?

    Thanks,
    fatzopilot

    #2
    This sounds like an exception thrown during dsRequest.execute(). If that doesn't seem to be the case, please post the full server log for the request so we can see where it's coming from.

    Comment


      #3
      Hi,

      I think (as can be seen from the trace attached) that my problem is the transaction into which the add operation is queued.
      The actual "db insert" operation does not take place on
      Code:
      dsRequest.execute()
      because the id is provided/generated by the application and thus hibernate does not need to immediately hit the database and instead queues the operation.
      That's why I cannot catch the exception here and it is instead thrown later when the catch block (and DMI method) has already been left.
      So what I need is something like
      Code:
      dsRequest.execute(true)
      or the like which immediately causes hibernate to commit all transactions/prevents them from being queued.
      Is there something like this (or another approach that lets me catch and handle the exception in the DMI?

      Thanks,
      fatzopilot

      Code:
      Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
      	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
      	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
      	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
      	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
      	at org.codehaus.groovy.grails.orm.hibernate.events.PatchedDefaultFlushEventListener.performExecutions(PatchedDefaultFlushEventListener.java:46)
      	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
      	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
      	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
      	at com.isomorphic.hibernate.HibernateTransaction.commitTransaction(HibernateTransaction.java:283)
      	at com.isomorphic.hibernate.HibernateTransaction.commitTransaction(HibernateTransaction.java:244)
      	at com.isomorphic.hibernate.HibernateDataSource.onSuccess(HibernateDataSource.java:5577)
      	at com.isomorphic.rpc.RPCManager.onSuccess(RPCManager.java:1583)
      	at com.isomorphic.rpc.RPCManager.completeResponse(RPCManager.java:1123)
      	at com.isomorphic.rpc.RPCManager.send(RPCManager.java:586)
      	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:173)
      	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:138)
      	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:74)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.processFilterChain(UrlMappingsFilter.java:416)
      	at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:243)
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:206)
      	at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:152)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.codehaus.groovy.grails.plugins.gwt.GwtCacheControlFilter.doFilter(GwtCacheControlFilter.java:57)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
      	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
      	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
      	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:380)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
      	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
      	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.shiro.grails.SavedRequestFilter.doFilter(SavedRequestFilter.java:55)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
      	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at javax.servlet.FilterChain$doFilter.call(Unknown Source)
      	at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:44)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:724)
      Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into attachment (version, contract_id, date_created, deleted, file_date_created, file_filename, file_filesize, last_updated, id) values (0, 41, '2013-09-29 18:04:31.758000 +00:00:00', '0', '2013-09-29 18:04:31.693000 +00:00:00', 'Smartgwt.odt', 12640, '2013-09-29 18:04:31.758000 +00:00:00', 3566716329135493262) was aborted.  Call getNextException to see the cause.
      	at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2746)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1887)
      	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:405)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2893)
      	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
      	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
      	... 81 more

      Comment


        #4
        We don't know of a Hibernate API that is guaranteed to cause this exception to happen earlier.

        What we'd recommend is manually checking for whatever condition can cause this error to arise, so you can throw an Exception during normal DMI processing.

        If you find out about a Hibernate API that would cause this error to be reported earlier, and can provide some sample code for using it, we would take a look at whether we can offer an early detection flag.

        Comment

        Working...
        X