Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate and EJB

 
wu jong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we intend to develop a j2ee app using ejbs and the struts framework in the middle and jsp in the front. also expected is a mysql backend accessible via hibernate layer from the ejbs.

for the above scenario, how/where should the transaction management be done ? are there any additional guidelines ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have decided to use EJB, then the how and where is probably Container Managed Transactions from the EJB. I'm sure you will be aware of this too, but make sure you use a mydsql database engine which supports transactions because not all do.
 
wu jong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh so should I switch off the transaction management in hibernate. How can I make a CMP Transaction effectively roolback on my DAO that uses Hibernate internally ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that Hibernate/JDBC transactions are different from JTA transactions. If you are calling your Hibernate code from inside a CMT EJB method, you won't use the Hibernate transaction API directly at all. Typically Hibernate recommend a "Session per business (JTA) transaction" approach. This basically means when you call your DAO code from a business method it opens a session, and does a bunch of persistance stuff (possibly accross many DAO's). At this point you are working against the session, not the database. When the last persistance operation of your CMT method finishes, the session is flushed and closed. If you wan't to roll back any of the Hibernate operations which happened in this CMT you do it just as you would for any CMT method; the presence of Hibernate doesn't make a difference.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic