In hibernate 2.1, what is the best way to get a hibernate working in a container managed environment. The hibernate document from the hibernate website tells to configure JTATransactionFactory in the hibernate.cfg.xml to work in a container managed environment.
But when I do that it works with JBoss but it fails in WebSphere because internally the factory tries to obtain the UserTransaction from the java:comp/UserTransaction which is the violation of the j2ee spec. It is not sure how come it worked in JBoss.
In Hibernate3.0 there is a transaction factory for CMT which is CMTTransactionFactory but what is the equivalent in hibernate2.1?
Here is the configuration used in the cfg.xml file <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property> <property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</property>
The transaction code is like this
Session ses = SessionFactory.openSession(); Transaction tx = ses.beginTransaction(); // do some insert/update tx.commit();
Based on the document available in the hibernate website this is the idiom that is supposed to be worked in a managed and non-managed environment.