Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling Hibernate Session for Container Managed transactions

 
Srinivas Genji
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sridhar skrishnan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic