Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

stand-alone java app and hibernate transactions

Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a stand-alone java app (no UI, no containers, no Spring) but we are using a layered approach internally for this app.

Following is how we maintain the layers within this stand-alone java app

Service Orchestration --> Service(or Manager layer) --> DAO --> Hibernate (ORM) -->Oracle

The Service Orchestration layer as the name suggests orchestrates call to various services as part of the business flow of this app.
The services(Manager layer) in turn have business logic chunks and also have data handling code like grab and aggregate data as part of the business logic related activities.
The DAO we use is a generic DAO (java 5 generics approach) on top of Hibernate

We also need transaction handling. My question where do have all the transaction handling (beginTransaction, endTransaction, commit, rollback).
Ideally I feel The Manager layer is best but I was a bit skeptical of invading the Manager layer with all Hibernate transaction api code usage.

Is there a way I can neatly encapsulate the transaction handling and inject it in Manager layer surrounding the DAO calls rather than verbose beginTransaction - commit/rollback - endTransaction - transaction related exception handling code in the Manager layer.

The other approach I have seen is having a HibernateUtil class which has all transaction related logic and comes into play post DAO layer. This approach works when the business logic is simple dealing with persistence of a single entity but in case of complex business logic involving multiple dao's (entities) the transactions need to incept at a layer above.

Let me know your thoughts.


To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic