-
1. Re: Transaction is not active
iggi Feb 13, 2006 11:19 AM (in response to iggi)BTW, this is happening in 4.03SP1 and 4.04RC1.
-
2. Re: Transaction is not active
adrian.brock Feb 13, 2006 11:37 AM (in response to iggi)The transaction is dead, you can't enlist a transactional datasource in it.
This is your real question (I added it to the FAQ):
http://wiki.jboss.org/wiki/Wiki.jsp?page=RetryingTransactions -
3. Re: Transaction is not active
iggi Feb 13, 2006 4:22 PM (in response to iggi)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 ) { e.printStackTrace(); throw new DataException( e.getMessage() ); } return conn; }
-
4. Re: Transaction is not active
iggi Feb 14, 2006 12:21 PM (in response to iggi)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.