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