3 Replies Latest reply on Aug 9, 2007 4:11 AM by Mark Little

    Commit failed with rollBack Exception what should be done?

    Shai Bentin Newbie

      I'm running on JBOSS4.0.3SP1 with its default transaction manager. I have a scanario where I use a USER_TRANSACTION.

      Sometimes a Commit fails with a RollBack Exception. I'm wondering what should be done? Looking at the transaction status at that point I see that the status is STATUS_NO_TRANSACTION, I would have expected to have "MARKED_FOR_ROLLBACK". So do I explicitly call "transaction.rollback()" or has the transaction already rolledback at this point?

        • 1. Re: Commit failed with rollBack Exception what should be don
          Mark Little Master

          You should either download and read the JTA specification, or download and read the JBossTS documentation.

          If you get a TransactionRolledbackException then it's done what it says: rolled back the transaction. In your case it's no longer associated with your thread, hence the STATUS_NO_TRANSACTION. Why would you expect it to be makred for rollback?

          • 2. Re: Commit failed with rollBack Exception what should be don
            Shai Bentin Newbie

            I'm asking this for a reason, I guess I should have mentioned.

            I did read the spec, but also read stuff on the net about Jboss and got a little confused, as somewhere it mentioned that the spec is unclear on what should be returned as the status at that point. (There was even something in JBoss jira about it).

            My problem is that my application gets into situations where the transaction does not disassociate from the Thread and statys in a NOT_ACTIVE state. Always when this happens there is some kind of exception a short time before the problem starts. In all of these cases when I check the code the exception is caught whether it is runtime or not. In some of them the transaction scope is started via a session bean and I always called setRollbackOnly, in some it happened during a UserTransaction and I always called rollback on the transaction. The only time I did not call rollback was when it happened on commit in UserTrasnaction. Up until now I did not roll back the transaction since according to the spec it should have been rolled back by the manager when I got this rollback exception.

            I thought maybe this was my problem and I should have rolledback my UserTransaction manually as I do when I get a regular exception when running in the transaction scope.

            I guess my question is what can get my transaction to stay NOT_ACTIVE on my thread without being released until I restart JBoss, apart from not handeling a rollback or commit when getting an exception in the transaction scope?

            • 3. Re: Commit failed with rollBack Exception what should be don
              Mark Little Master

               

              "bentins" wrote:
              I'm asking this for a reason, I guess I should have mentioned.

              I did read the spec, but also read stuff on the net about Jboss and got a little confused, as somewhere it mentioned that the spec is unclear on what should be returned as the status at that point. (There was even something in JBoss jira about it).


              The JTA spec. is unclear on a few things, but it's clear on when you should expect "marked rollback only" versus "no transaction".


              My problem is that my application gets into situations where the transaction does not disassociate from the Thread and statys in a NOT_ACTIVE state.


              That could happen if the transaction is terminated via Transaction and not TransactionManager. Only the latter is guaranteed to break the thread-to-transaction association.


              Always when this happens there is some kind of exception a short time before the problem starts. In all of these cases when I check the code the exception is caught whether it is runtime or not. In some of them the transaction scope is started via a session bean and I always called setRollbackOnly, in some it happened during a UserTransaction and I always called rollback on the transaction. The only time I did not call rollback was when it happened on commit in UserTrasnaction. Up until now I did not roll back the transaction since according to the spec it should have been rolled back by the manager when I got this rollback exception.


              Yes, it definitely should have been rolled back by this point. But depending upon *how* it was rolled back you might still have the association.


              I thought maybe this was my problem and I should have rolledback my UserTransaction manually as I do when I get a regular exception when running in the transaction scope.

              I guess my question is what can get my transaction to stay NOT_ACTIVE on my thread without being released until I restart JBoss, apart from not handeling a rollback or commit when getting an exception in the transaction scope?


              JBossAS 4.0.3SP1 had some issues with using Transaction for termination when it should have been using TransactionManager. I thought we caught all of those issues when we were integration JBossTS, but it's possible we didn't catch them all until 4.0.5. Try upgrading your AS. If you can't upgrade, try doing a TM.suspend or (if TM is not available), rollback directly.