[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Calling datasource.getConnection() after sessionContext.setR

AlexFDT do-not-reply at jboss.com
Fri Aug 1 11:23:47 EDT 2008

I am adapting an old application which worked on JBOSS 2.1 to the new JBOSS server version. 
Now I am using JBOSS 5.0.0.Beta4.

There is a code in the application which acts like the following (simplified):

  | javax.ejb.SessionContext sessionContext = ...;
  | ...
  | if (somethingGoesWrong()) {
  |     sessionContext.setRollbackOnly();
  |     //Then get connection to the DB
  |     javax.sql.DataSource dataSource = ....;
  |     java.sql.Connection con = dataSource.getConnection();
  |     //and execute a query
  |     ...       
  | }

The following exception is thrown when "dataSource.getConnection()" executes:

  | org.jboss.util.NestedSQLException: Transaction is not active:
  | tx=TransactionImple < ac, BasicAction: -3f57fffe:745:48918030:537 status: ActionStatus.ABORT_ONLY >; 
  | - nested throwable: (javax.resource.ResourceException: Transaction is not active: 
  | tx=TransactionImple < ac, BasicAction: -3f57fffe:745:48918030:537 status: ActionStatus.ABORT_ONLY >)
  |      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)

Is it a JBOSS bug or such code really should not work?

I tried to debug using JBOSS sources. The exception is thrown from org.jboss.resource.connectionmanager.TxConnectionManager:

  | public ConnectionListener getManagedConnection(Subject subject, ConnectionRequestInfo cri)
  |       throws ResourceException
  |    {
  |       Transaction trackByTransaction = null;
  |       try
  |       {
  |          Transaction tx = tm.getTransaction();
  |          if (tx != null && TxUtils.isActive(tx) == false)
  |             throw new ResourceException("Transaction is not active: tx=" + tx);
  |      ...
So if transaction is not in Status.STATUS_ACTIVE (TxUtils.isActive(tx)) then throw an exception.
Link to current source:

Older version of this class used another check method:

  | ...
  | if (trackConnectionByTx && tm.getStatus() != Status.STATUS_NO_TRANSACTION)
  |             tx = tm.getTransaction();
  | ...
Link to older source:

If transaction is not in Status.STATUS_NO_TRANSACTION then it is ok.

Older version of TxUtils.isActive(Transaction tx) was also functioning in the different way.

Old: TxUtils.isActive() returns true if the transaction is in Status.STATUS_ACTIVE or Status.STATUS_MARKED_ROLLBACK.

Current: TxUtils.isActive() returns true if the transaction is in Status.STATUS_ACTIVE. 

All these changes were made corresponding to this issue: https://jira.jboss.org/jira/browse/JBAS-1916.

TxUtils.isActive() - it is ok. But I can not understand why TxConnectionManager changed to the way it works now.

If I did not read some documentation please direct me to it.

Thanks for all people who will answer something or even read this to the end. :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4168205#4168205

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4168205

More information about the jboss-user mailing list