4 Replies Latest reply on Aug 25, 2010 6:40 AM by jaikiran pai

    setRollbackOnly() not rolling back completely

    M Arnold Newbie

      I have an MDB using container managed transactions (REQUIRED) which calls methods in a stateless session bean (also container managed transaction and REQUIRED) which in turns makes JDBC calls to make database changes.

       

      In the session bean, if it gets a SQLException making JDBC calls, I call setRollbackOnly(), and rethrow the exception.  When the MDB gets this SQLException, it also calls setRollbackOnly(), though I understand thats not necessary, since the session bean should've inherited its transaction, which it marked to rollback.

       

      What I see when a SQLException occurs, is that the message is still on the queue (so the JMS dequeue is rolled back) but the database changes are committed.

       

      I expect to see both the JMS dequeue and the JDBC calls rolled back together... so this is very troubling!

       

      I'm using JBoss 5.1 JRE 6, Oracle 10gR2, an XA DataSource.  There are no JDBC commits in my code.  All CallableStatements, Connections are closed properly.

       

      I would really appreciate some help, or some guidance on how to investigate further as I am stuck.

       

      If I'm not doing something wrong that's immediately obvious, I can try to reduce to a small repeatable test case.

       

      Thanks, Malcolm

        • 1. Re: setRollbackOnly() not rolling back completely
          jaikiran pai Master

          Do you use a transaction aware resource like a datasource to communicate with the DB? Plain JDBC statements will not be enrolled in the transaction.

          • 2. Re: setRollbackOnly() not rolling back completely
            M Arnold Newbie

            jaikiran pai wrote:

             

            Do you use a transaction aware resource like a datasource to communicate with the DB? Plain JDBC statements will not be enrolled in the transaction.

            Yes, I am using a transaction aware DataSource.  I configured it along the lines of this Wiki: http://community.jboss.org/wiki/SetupAOracleDataSource.  (I've tried both local TX and XA datasources.)

             

            I have JMS and JDBC transactions commiting and rolling back together successfully using a container managed transaction where both the JMS and JDBC work are performed by a single session bean.

             

            The difference is that here the JDBC work is performed in a session bean and the JMS work performed implicitly by an MDB.  I have @TransactionAttribute(TransactionAttributeType.REQUIRED) on the session bean so my understanding is that it will perform its work in the same transaction as the MDB onMessage().

             

            Regardless of whether the session bean uses a separate transaction as the MDB or not, I am calling setRollbackOnly() so I expect the JDBC work to be rolled back.... it's not.

            • 3. Re: setRollbackOnly() not rolling back completely
              M Arnold Newbie

              Hi everyone - please ignore this question.  I am actually an idiot, and it's all working correctly.  I got confused because my MDB was sent two messages - one worked and committed correctly - the other didn't and was rolled back correctly.

               

              Sorry to everyone who took the time to read and consider my question.

              • 4. Re: setRollbackOnly() not rolling back completely
                jaikiran pai Master

                Thanks for posting those details here.

                 

                M Arnold wrote:

                 

                Sorry to everyone who took the time to read and consider my question.

                No problem, it happens to everyone