• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where should we hide our transaction begin & commit calls?

 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to decide where I should code a transaction (txn).begin and transaction (txn).commit method.

I've seen them put in DAO objects, using the DAO pattern, but DAO objects should be independent of the underlying database, database connection mechanism, and txn mechanism. So, why ask a developer using Hibernate to put a txn.begin method in there that uses Hibernate, when at deployment time, you may use JTA? So, I don't like it in the DAO. Maybe I'm wrong?

Right now I've got it in a HibernateUtil class, but that just looks silly. I've got a real elegant DAO that abstracts out everything, and right above and below calls to he DAO, I've got this class called HibernateUtil that obviously is tightly tied to the hibernate implementation.

Should the tranaction mechanism be looked up through a ServiceLocator pattern? Thus allowing the implementation of the txn mechanism to be switched in and out easily? So, I'd grab the txn through the ServiceLocator, and then, begin the txn, and then invoke the DAOs, which are implemented by Hibernate under the covers?

Overall, I've got a very elegant design, but my the lack of abstraction on the txn part is far from elegant.

-Cameron McKenzie
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you thought about using transactions declaratively.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic