4 Replies Latest reply on Aug 3, 2009 9:07 AM by magix

    Transaction rollbacks - how to control them

    magix

      Hi,


      Yuan/Heute write in their book JBoss Seam





      By default, the transaction is rolled back only when an unchecked exception occurs.



      But in my case this doesn't seem to work: in a delete action, where the db complains about a constraint violation exception and a unchecked exception is thrown, seam tries to rollback the transaction, but then the following error appears: could not roll back transaction java.util.EmptyStackException.
      Why that? Here's the stack trace.







      Caused by: java.sql.SQLException: ORA-02292: integrity constraint (REVE.EZSE_SETT_FK) violated - child record found
      
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
           at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
           at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
           at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
           at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219)
           at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:970)
           at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1190)
           at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3370)
           at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3454)
           at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365)
           at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2523)
           ... 97 more
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 WARN  [ExceptionFilter] running exception handlers
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [FacesLifecycle] >>> Begin exception recovery
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [Manager] Restoring conversation with id: 30
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [ExceptionFilter] killing transaction
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [UTTransaction] rolling back JTA transaction
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 ERROR [ExceptionFilter] could not roll back transaction
      java.util.EmptyStackException
           at java.util.Stack.peek(Stack.java:85)
           at java.util.Stack.pop(Stack.java:67)
           at org.jboss.seam.transaction.SeSynchronizations.afterTransactionRollback(SeSynchronizations.java:45)
           at org.jboss.seam.transaction.UTTransaction.rollback(UTTransaction.java:70)
           at org.jboss.seam.web.ExceptionFilter.rollbackTransactionIfNecessary(ExceptionFilter.java:159)
           at org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(ExceptionFilter.java:113)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Thread.java:619)
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [FacesManager] redirecting to: /reve/error.seam?cid=30
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [FacesLifecycle] After render response, destroying contexts
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [FacesLifecycle] <<< End JSF request for /reve/ReveSettoriEdit.seam
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [ExceptionFilter] done running exception handlers
      15:14:52,018 INFO  [STDOUT] 15:14:52,018 DEBUG [BaseFilter] Finished request processing total time 31ms for uri: /reve/ReveSettoriEdit.seam
      15:14:52,472 INFO  [STDOUT] 15:14:52,472 DEBUG [BaseFilter] Filter start request processing at 27.07.09 15:14  for uri: /reve/error.seam
      15:14:52,472 INFO  [STDOUT] 15:14:52,472 DEBUG [BaseFilter] Filter request output to XML
      15:14:52,472 INFO  [STDOUT] 15:14:52,472 DEBUG [BaseXMLFilter] XML filter service start processing request
      
      
      





      On the other side if I catch the exception the transaction is rolled back properly.
      Also this behaviour is not what I would expect as Yuan gives only three possibilites to force a rollback:








      1. RuntimeExceptions

      2. raise a @ApplicationException

      3. use @Rollback with return-value



      What do I miss here?


      Matthias


        • 1. Re: Transaction rollbacks - how to control them
          jeanluc

          Put breakpoints in SeSynchronizations to understand the flow (it's a simple class). Also doublecheck you have <transaction:ejb-transaction /> in your components.xml


          • 2. Re: Transaction rollbacks - how to control them
            mrossix


            Do you mean this works only with <transaction:ejb-transaction /> ??



            • 3. Re: Transaction rollbacks - how to control them
              asookazian

              as per Seam ref docs: 



              In an EJB3 environment, we recommend the use of a special
              built-in component for transaction management, that is fully aware of container transactions,
              and can correctly process transaction success events registered with the Events component. If
              you don't add this line to your components.xml file, Seam won't know when container-managed
              transactions end.

              If you're using EJB3 components, it's in your best interest to add that line in your components.xml.


              I'm not sure what happens if you add that line and then mix and match EJB3 and JavaBean (@Transactional) components.

              • 4. Re: Transaction rollbacks - how to control them
                magix

                Jean Luc wrote on Jul 27, 2009 22:42:


                Also doublecheck you have <transaction:ejb-transaction /> in your components.xml




                But I'm not using EJBs. So I do not have to add this to my components.xml, right?


                Matthias