Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

With respect to using CMT Transactions in SessionBeans and Hibernate

 
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?
 
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic