Meaningless Drivel is fun!
The moose likes Object Relational Mapping and the fly likes Hibernate and Container Managed Transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate and Container Managed Transaction" Watch "Hibernate and Container Managed Transaction" New topic

Hibernate and Container Managed Transaction

Sethu Nambiar

Joined: Oct 22, 2005
Posts: 12
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

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.

Any suggestions would be greatly appreciated.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
You might want to check the JNDI name in the configuration file, and in WebSphere management page, and make sure that they are equals.

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Sethu Nambiar

Joined: Oct 22, 2005
Posts: 12
JNDI lookup name and all other configurations are correct.
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
<bean id="idofs" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${ jndi.datasource}" />

in websphere use adminconsle to configure the websphere.
Sethu Nambiar

Joined: Oct 22, 2005
Posts: 12
I am not using spring for Hibernate related work.
I agree. Here's the link:
subject: Hibernate and Container Managed Transaction
It's not a secret anymore!