1 2 Previous Next 16 Replies Latest reply on Nov 23, 2007 10:19 AM by adrian.brock Go to original post
      • 15. Re: Opening connection from a marked rollback tx

        That makes sense. I don't know if I can reproduce the problem in a reasonably small test case. I can try, but I currently lack the time.

        • 16. Re: Opening connection from a marked rollback tx

           

          "oglueck" wrote:
          That makes sense. I don't know if I can reproduce the problem in a reasonably small test case. I can try, but I currently lack the time.


          Try

          // BMT bean
          public void recreateRandomRollbackOnly() throws Exception
          {
           UserTransaction ut = ..
           ut.setTransactionTimeout(5); // 5 second timeout
           ut.begin();
           try
           {
           try
           {
           Thread.sleep(10000); // 10 second sleep
           }
           catch (InterruptedException ignored)
           {
           }
          
           // Transaction has timed out here
          
           DataSource ds = ...;
           ds.getConnection().close(); // Oops can't enlist in dead transaction
           }
           finally
           {
           ut.rollback();
           }
          }
          


          http://java.sun.com/javaee/5/docs/api/javax/transaction/Transaction.html#enlistResource(javax.transaction.xa.XAResource)

          RollbackException - Thrown to indicate that the transaction has been marked for rollback only.
          IllegalStateException - Thrown if the transaction in the target object is in the prepared state or the transaction is inactive.


          If you need to do out-of-bound communication (i.e. read the database
          even if the transaction has failed) then you need to use a different transaction,
          either RequiresNew or no-tx-datasource.

          There's nothing you can do in the dead transaction.

          1 2 Previous Next