-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with JTA in WAS (5.0)
PostPosted: Fri Aug 19, 2005 10:47 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
Hi!

We use Hibernate 3.0.5 in WAS 5.0 in the Webcontainer only (at the moment). We use delegate to the JTA trx manager:

Code:
<property name="connection.datasource">java:comp/env/jdbc/rzbdrd_oratgr_xa</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="max_fetch_depth">3</property>


We initialize the sessionFactory at the first call to openSession().
As we know WAS starts a "Local Transaction Context" (LTC) at the servlet entry which gets suspended during a UserTransaction (think this is WAS specific, J2EE spec leaves this to implementors). The problem now is, that when the sessionFactory initializes, the LTC is set to status "in work" internally, which causes a UserTransaction afterwards to fail with the following exception (happens only with XA Data Sources):

Code:
2005-08-19 12:45:23,023 ERROR [org.hibernate.transaction.JTATransaction] JTA transaction begin failed
javax.transaction.NotSupportedException: java.lang.IllegalStateException: Cannot start a global transaction. A LocalTransactionContainment is already active with work.
   at com.ibm.ejs.jts.jta.UserTransactionImpl.begin(UserTransactionImpl.java:173)
   at org.hibernate.transaction.JTATransaction.begin(JTATransaction.java:73)
   at org.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:53)
   at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271)
   at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079)
   at at.rsf4j.core.db.hibernate.RSFHibernateConnectionManager.beginTransaction(RSFHibernateConnectionManager.java:261)
   at at.rsf4j.core.db.hibernate.RSFHibernateConnectionManager.getSession(RSFHibernateConnectionManager.java:214)
   at at.rsf4j.core.db.hibernate.RSFHibernateConnectionManager.getSession(RSFHibernateConnectionManager.java:155)
   at at.rsf4j.core.db.hibernate.RSFHibernateManager.getSession(RSFHibernateManager.java:112)
   at at.rzb.drd.proxy.RZBDrdBLL.saveDeal(RZBDrdBLL.java:215)


At subsequent requests the sessionFactory is already initialized and no exception occurs. Our workaround would be to initialize the sessionFactory at servlet startup. Is this the recommended way?

One more question: We always use the Hibernate Transaction API, namely sessionFactory.openSession(). If we change to a container managed environment, can I still use openSession() or do I have to adapt the code to use Session.getCurrentTransaction() then (including removing all transaction handling)? I see that it may make my life easier, but is it correct that I can also use openSession() in a container managed environment?

best regards
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 12:37 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
I now found a workaround for the problem

The problem was that the call to configuration.buildSessionFactory() seems to open a local transaction under WAS 5.0.

I now changed the call to buildSessionFactory() such that a global transaction is already running during this call. Then no local transaction is opened and it works:

Code:
Context c = new InitialContext();
UserTransaction ut = (UserTransaction) c.lookup("java:comp/UserTransaction");
ut.begin();
configuration.configure();
sessionFactory = configuration.buildSessionFactory();
ut.commit();



I wonder whether it would make sense to insert code similar to this to Hibernate's method buildSessionFactory()? It would be code similar to the one in org.hibernate.transaction.JTATransaction.begin().
Of course, it would be necessary to check if buildSessionFactory is called under a JTA context.

regards,
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 2:24 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
Finally I found the real reason for my problem: It was my Oracle Driver.

I had the Oracle Driver for version 9.2.0.3.
When I upgraded it to the one for 10.1.0.2.0, the error did not occur anymore. (This works even tough I'm still using an Oracle 9 database.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.