Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a (widely) accepted architecture regarding the use of Hibernate?

 
B. Stinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

I'm new to these here parts and I have (what I think is) a basic question:

Is there any accepted architecture to use with Hibernate?

I got the basic DAO design to work which I learned from the book: Java Persistence with Hibernate (by Bauer/King). But I'm lost on how to use it. Am I supposed to replace every handwritten SQL statement with the appropriate DAO? Because that kind of seems messy to me (large legacy project)

Aside from frameworks like Spring, how do you people put Hibernate to work?

Any help will be appreciated.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DAO pattern is separate from Hibernate - Hibernate is after all an implementation of a particular type of data access. The normal pattern would be to have CRUD methods for each entity accessed via an appropriate DAO class, so yes, the DAO implementation abstracts your SQL (or since this is Hibernate HQL, Criteria query or Session interaction).

If its a large legacy project the DAO pattern is even more useful; it gives you a chance to make a clean break from the old data model. New code written doesn't need to expose the mistakes of the past. Unfortunately "large" means you will probably have a lot of grunt work to churn out the initial DAO classes.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stinson,
Welcome to javaranch.
Check the OpenSessionInView pattern.
 
B. Stinson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you two for your answers.

I'll have a look into that pattern.

The DAO architecture is quite elegant as I think. My main concern is all the many different classes that need to use the DAOs. I thought maybe there's something like a "service" layer concept. So one(or more) class that implements business functions such as: "findLastOrderOfMoth" etc which uses all the DAOs it needs to.

Then I would only have one(or at most: some) location where I could check on the usage of the DAOs. This would be nice in case I added a method to the GenericDAO. Something every DAO needs to call from now on before using its other methods. Imagine to look through every class and every method just to see if any DAO is used there...

Is there anything comparable? Or do I have to implement the way I think and see if it works?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic