title: J2CA0081E Websphere 6 Exception
body: <p>Occasionally I see this exception. It affects some of the crucial business processes in the application. What could it be? Did anyone have similar error?</p>
  
  <p>I use WebSphere 6 with OJDBC14 &amp; Hibernate 3.</p>
  
  <pre><code>[21.02.14 06:46:03:209 PST] 00000031 MCWrapper     E   J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@4d34b403 from ressource jdbc/MYDS. Caught exception: com.ibm.ws.exception.WsException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..
      at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.&lt;init&gt;(DataStoreAdapterException.java:226)
      at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.&lt;init&gt;(DataStoreAdapterException.java:177)
      at com.ibm.ws.rsadapter.AdapterUtil.createDataStoreAdapterException(AdapterUtil.java:232)
      at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.cleanupTransactions(WSRdbManagedConnectionImpl.java:3392)
      at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.cleanup(WSRdbManagedConnectionImpl.java:3025)
      at com.ibm.ejs.j2c.MCWrapper.cleanup(MCWrapper.java:1353)
      at com.ibm.ejs.j2c.poolmanager.FreePool.returnToFreePool(FreePool.java:462)
      at com.ibm.ejs.j2c.poolmanager.PoolManager.release(PoolManager.java:1543)
      at com.ibm.ejs.j2c.MCWrapper.releaseToPoolManager(MCWrapper.java:2031)
      at com.ibm.ejs.j2c.ConnectionEventListener.connectionClosed(ConnectionEventListener.java:263)
      at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.processConnectionClosedEvent(WSRdbManagedConnectionImpl.java:1477)
      at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.closeWrapper(WSJdbcConnection.java:724)
      at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java(Compiled Code))
      at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java(Compiled Code))
      at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:74)
      at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:445)
      at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:379)
      at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:318)
      at org.hibernate.impl.SessionImpl.close(SessionImpl.java:293)
  </code></pre>
  
  <p>Update: This happens when I do session.close() in finally block. Something like this:</p>
  
  <pre><code>try {
      tx = session.beginTransaction();
  
      // some code
  
      if (!tx.wasRolledBack() &amp;&amp; !tx.wasCommitted()) {
          tx.commit();
      }
  } catch (Exception ex) {
      // rollback transaction in case of errors
  }
  finally {
      session.close(); // Exception happens here!
  }
  </code></pre>