aspose file tools*
The moose likes Object Relational Mapping and the fly likes Where should we hide our transaction  begin & commit calls? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Where should we hide our transaction  begin & commit calls?" Watch "Where should we hide our transaction  begin & commit calls?" New topic
Author

Where should we hide our transaction begin & commit calls?

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

have you thought about using transactions declaratively.


If you are not laughing at yourself, then you just didn't get the joke.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where should we hide our transaction begin & commit calls?