4 Replies Latest reply on Feb 14, 2006 12:21 PM by Jonathan Sharley

    Transaction is not active

    Jonathan Sharley Newbie

      I'm having trouble retrieving connections from my <local-tx-datasource> pool. Whenever a SQL connection exceeds the query-timeout, it seems to "break" that connection in the pool. I see the following line appear in my log:

      08:53:07,949 WARN [TransactionImpl] Transaction TransactionImpl:XidImpl[FormatId=257, GlobalId=utopia/50, BranchQual=, localId=50] timed out. status=STATUS_ACTIVE

      The next time I try to grab the connection via DataSource.getConnection()
      it throws the "Transaction is not active" error:

      08:53:34,836 ERROR [STDERR] Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=utopia/50, BranchQual=, localId=50]
      08:53:34,836 ERROR [STDERR] at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:287)
      08:53:34,836 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:368)
      08:53:34,836 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:797)
      08:53:34,837 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)

      This problem occurs with both MySQL and Oracle pooled connections. I've tried setting the <check-valid-connection> in the *-ds.xml file, but that doesn't seem to help. Any ideas what could be causing this?

      How can I reset the bad connections?

        • 1. Re: Transaction is not active
          Jonathan Sharley Newbie

          BTW, this is happening in 4.03SP1 and 4.04RC1.

          • 2. Re: Transaction is not active
            Adrian Brock Master

            The transaction is dead, you can't enlist a transactional datasource in it.

            This is your real question (I added it to the FAQ):

            • 3. Re: Transaction is not active
              Jonathan Sharley Newbie

              Thank you for your response. However, I?m still unclear as to what I need to do to fix the issue in my code. The example about RetryingTransactions is referring to an EJB, and my code is in a simple servlet running in Tomcat under JBoss.

              The snippet of code below is my method for obtaining a JTA connection from the pool. As you can see it does the JNDI lookup, fetches the DataSource object, and tries to return a Connection object. Once I have the DataSource, how can I determine if the connection I get will be dead? Or, if I trap the exception, how can I remove the dead transaction from the pool and get a live one?

              private static Connection getJBossJTAConnection(String poolName) throws DataException
               Connection conn = null;
               try {
               InitialContext ctx = JNDIManager.getInstance().getInitialContext();
               DataSource ds = (DataSource)ctx.lookup("comp/env/jdbc/" + poolName + "Tx");
               conn = ds.getConnection();
               catch ( Exception e ) {
               throw new DataException( e.getMessage() );
               return conn;

              • 4. Re: Transaction is not active
                Jonathan Sharley Newbie

                I discovered the source of the issue. When a UserTransaction times out the tx.getStatus() == Status.STATUS_MARKED_ROLLBACK.

                After a timeout, my next servlet call would fetch the UserTransaction object via JNDI and JBoss was happy to hand it back the last transaction in progress ( the dead, timed out one).

                Previously on requesting a transaction I had only been checking for either Status.STATUS_ACTIVE or Status.STATUS_NO_TRANSACTION. In this case I needed to check for the STATUS_MARKED_ROLLBACK condition and explicitly call tx.rollback() and tx.begin() so that my next DataSource.getConnection wouldn't try to use the dead transaction.