-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Working with transactions using Hibernate 3.1 on WebSphere 6
PostPosted: Thu Feb 27, 2014 2:48 am 
Newbie

Joined: Thu Feb 27, 2014 2:31 am
Posts: 2
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? :)


Top
 Profile  
 
 Post subject: Re: Working with transactions using Hibernate 3.1 on WebSphere 6
PostPosted: Thu Feb 27, 2014 4:13 am 
Newbie

Joined: Thu Feb 27, 2014 2:31 am
Posts: 2
By the way here is the thing. I have my Web Application running on WebSphere 6 and also there are some quartz scheduler tasks. If do the lookup like that:
Code:
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

It works fine with my Web Application, but any threads initiated by quartz timers fails to access the DB using that lookup.
But if I use
Code:
<property name="jta.UserTransaction">jta/usertransaction</property>

Then it is the opposite. I will get quartz timers working but I can't do the lookup inside my Web Application.

Probably all the issues will be solved if I find a way to make them both working with same configuration.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.