This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes hibernate with Container Managed Transactions (CMT) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate with Container Managed Transactions (CMT)" Watch "hibernate with Container Managed Transactions (CMT)" New topic

hibernate with Container Managed Transactions (CMT)

abd hassan
Ranch Hand

Joined: Jul 15, 2003
Posts: 38
I'm new to hibernate and trying to learn this technology. I'm trying to see how I can use hibernate in my domain layer with existing session beans facades in my service layer. How would transaction management work in this case. I'm currently running on websphere 5.1. I still want to use CMTs and let the container handle transactions set on my session beans instead of using explicit hibernate transactions. Is that feasible ? Is there any particular configuration setting required in hibernate to achieve that? Also, I usually hear about projects in which hibernate is used with Spring. How about the architecture where you have ejb session facades with hibernate. Is that a common approach ? Thanks for your help.
abd hassan
Ranch Hand

Joined: Jul 15, 2003
Posts: 38
anybody ??
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Your approach is fine. Actually when you have a Hibernate Session and call beginTransaction on your Hibernate Sesison, and you currently have a CMT Transaction from your EJB, Hibernate will use and join that Transaction, rather than it "creating" its own. So if you rollback your CMT Transaction, all the stuff you used Hibernate for with data will also be rolled back.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
abd hassan
Ranch Hand

Joined: Jul 15, 2003
Posts: 38
Thanks so much. But there is another question. Why would you even bother to use hibernate explicit transaction management if you can handle it declaratively using CMT on a session facade. Also, I found this:

This seems to suggest that if you're using Websphere (which I am), then you'll have problem looking up the Container Transaction Manager. Maybe this is old information and the problem is fixed. I'm not sure. Please let me know if I'm missing something.

Dhawal Shah

Joined: May 09, 2006
Posts: 2

Check this IBM Technical article. I have successflly configured Hibernate to work with Websphere Transaction Management.

Good luck.

chets patel
Ranch Hand

Joined: Apr 27, 2010
Posts: 77

Hi Dhawal
Can you please tell me is it possible to use CMT in hibernate without EJB
I dont know EJB at all but I want to use CMT in hibernate.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No. CMT is an intrinsic part of the EJB technology. If you want to use it, you need to be using EJB.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
chets patel
Ranch Hand

Joined: Apr 27, 2010
Posts: 77

Thanks for your reply.

I heard that its possible with Spring. Is it correct?
Sanjiv Tripathi

Joined: Jan 12, 2012
Posts: 1
CMT is a form of declarative transaction management , it is possible with Spring's declarative transaction management using Spring AOP.
I agree. Here's the link:
subject: hibernate with Container Managed Transactions (CMT)
It's not a secret anymore!