db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julius Stroffek <Julius.Strof...@Sun.COM>
Subject The XAConnection could be closed if there is no global transaction associated
Date Fri, 13 Apr 2007 09:20:22 GMT
When I execute the following piece of code (using trunk)

                XAConnection xaConn = createXAConnection(connString, "", 
"");
                XAResource xaRes = xaConn.getXAResource();
                Connection conn = xaConn.getConnection();
               
                xaRes.setTransactionTimeout(3);
                Xid xid = createXid(i);
               
                conn.setAutoCommit(false);
               
                xaRes.start(xid, XAResource.TMNOFLAGS);
                stm = conn.createStatement();
               
                stm.execute(query);
               
                xaRes.end(xid, XAResource.TMSUCCESS);
                xaConn.close();

I go the following exception

java.sql.SQLException: Cannot close a connection while a transaction is 
still active.
        at 
org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown 
Source)
        at 
org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
        at org.apache.derby.client.am.Connection.closeResourcesX(Unknown 
Source)
        at org.apache.derby.client.am.Connection.closeResources(Unknown 
Source)
        at 
org.apache.derby.client.net.NetConnection.closeResources(Unknown Source)
        at org.apache.derby.client.ClientPooledConnection.close(Unknown 
Source)
        at org.apache.derby.client.ClientXAConnection.close(Unknown Source)
        at XATranTest.test3(XATranTest.java:61)
        at XATranTest.main(XATranTest.java:22)
Caused by: org.apache.derby.client.am.SqlException: Cannot close a 
connection while a transaction is still active.
        at 
org.apache.derby.client.am.Connection.checkForTransactionInProgress(Unknown 
Source)
        ... 7 more

It was possible to close the XAConnection object some time ago also when 
there was a transaction associated with the connection - see DERBY-2420.

The above code should be allowed. The JDBC spec says:
/The transaction manager is not required to use the same XAResource 
object to
commit/rollback a transaction branch as was used to execute the branch. 
If different
XAResource objects are used, however, they must be associated with
XAConnection objects that connect to the same resource manager.//

/And because there is 1:1 relation between XAConnection and XAResource 
instances the application may use a different connection later to 
commit/rollback the transaction. The discussion about this is present on 
DERBY-2220.

Does anybody know in which JIRA the change was made? Or how can I figure 
that out using svn command?

Thanks a lot,

Julo

Mime
View raw message