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?
I use WebSphere 6.0.2.15 with OJDBC14 (v10.2.0.5.0) & Hibernate 3.1.3.
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.(DataStoreAdapterException.java:226) at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.(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)
This happens when I do
Code:
session.close()
in finally block. Something like this:
Code:
SessionFactory sessionFactory = null;
Context ctx = null;
Object obj = null;
ctx = new InitialContext();
obj = ctx.lookup("HibernateSessionFactory");
sessionFactory = (SessionFactory) obj;
session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
// some code
if (!tx.wasRolledBack() && !tx.wasCommitted()) {
tx.commit();
}
} catch (Exception ex) {
// rollback transaction in case of errors
}
finally {
session.close(); // Exception happens here!
}
I am not using Spring beans or EJBs. Just plain Hibernate with POJOs.
I believe the cause of the problem is that WebSphere and Hibernate both try to manage the transaction at the same time.
I tried to add those lines to hibernate.cfg.xml to start using JTA UserTransaction without any other code changes:
Code:
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
<property name="jta.UserTransaction">jta/usertransaction</property>
Then I get an exception when the program flow reaches transactional code:
Code:
W NMSV0605W: A Reference object looked up from the context "localhost/nodes/localhost/servers/server1" with the name "jta/usertransaction" was sent to the JNDI Naming Manager and an exception resulted. Reference data follows:
Reference Factory Class Name: com.ibm.ws.Transaction.JTA.UtxJNDIFactory
Reference Factory Class Location URLs: <null>
Reference Class Name: java.lang.Object
Exception data follows:
javax.naming.ConfigurationException
at com.ibm.ws.Transaction.JTA.UtxJNDIFactory.getObjectInstance(UtxJNDIFactory.java:107)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:314)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:894)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookup(Helpers.java:701)
at com.ibm.ws.naming.jndicos.CNContextImpl.processResolveResults(CNContextImpl.java:1937)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1792)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1707)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1412)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1290)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:145)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:53)
at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:177)
at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1279)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1289)
Could someone help me to solve this puzzle? :)