aspose file tools*
The moose likes Object Relational Mapping and the fly likes Handling Hibernate Session for Container Managed transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Handling Hibernate Session for Container Managed transactions" Watch "Handling Hibernate Session for Container Managed transactions" New topic
Author

Handling Hibernate Session for Container Managed transactions

Srinivas Genji
Ranch Hand

Joined: May 04, 2004
Posts: 37
Hi Eveyryone,

I started using Hibernate and can any one explain how to handle Container Managed transaction. Here is my sample design

I have stateless session Bean and DAO (Hibernate) layer, session bean class has multiple DAO calls in a single session bean method. Reason behind Stateless session bean is to handle Container Managed Transaction. So Can any one help me how to handle CMT. How to create Hibernate Session, Can I use Session.openSession() or currentSession() ........... Provide some details on this.


Genji B Srinivas<br />M.Tech (IT) Aus
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

You will still code the same way, with openSession() then beginTransaction(), and then commit()/rollback() and close() when you are done with the session. Hibernate is smart enough to use the CMT transaction, instead of creating its own Transaction object. So the commit() will not commit the CMT transaction, because there might be more stuff the CMT is doing, Hibernate is smart to do the right thing, so all you have to do is code it just like it wasn't in CMT, the code looks the exact same, no differences.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
sridhar skrishnan
Greenhorn

Joined: Dec 24, 2007
Posts: 10
How does it work? I tried using CMTTransactionFactory. The app threw an exception when it encountered session.beginTransaction. However, If i take that code snippet off, its works fine....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling Hibernate Session for Container Managed transactions