Forums Register Login

Where should we hide our transaction begin & commit calls?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
have you thought about using transactions declaratively.
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 841 times.
Similar Threads
Where to use persist and transaction
where can I find persistence.HibernateUtil
Data Access Objects: static methods
BMP Vs CMP
How to limit resultset size through hibernate.cfg.xml?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:58:08.