Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

With respect to using CMT Transactions in SessionBeans and Hibernate

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi .

I have some operations to be performed on the Database . I am using Session Beans and Hibernate for this.

While performing an insertion operation should i set the transaction support from a session Bean using CMT Or

Will it be a good practice to use Transaction in DAO implementation code with the help of Hibernate provided Transaction suppourt.

Please tell me what will be the best approach?
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose it'll be good idea to use your Stateless Session Bean's transaction rather than in the DAO.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviNada Kiran wrote:
Hi .

I have some operations to be performed on the Database . I am using Session Beans and Hibernate for this.

While performing an insertion operation should i set the transaction support from a session Bean using CMT Or

Will it be a good practice to use Transaction in DAO implementation code with the help of Hibernate provided Transaction suppourt.

Please tell me what will be the best approach?


It depends where you need your transactions to start/end. Usually that will be the EJB method but it might not always be the case.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will be better to start the Transactions in the EJB because
If you have to insert data in two different tables in one transaction, and you are using two different DAOs for those two tables, then its better to start the transaction in the EJB, call the two DAOs in the same transaction..
Also, it is better on rely on CMT unless you explicitly need the control of the transactions to yourself...
But as Paul mentioned, might not always be the case...
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point Rahul .Thanks.

Thanks Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic