File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Is there a (widely) accepted architecture regarding the use of Hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Is there a (widely) accepted architecture regarding the use of Hibernate?" Watch "Is there a (widely) accepted architecture regarding the use of Hibernate?" New topic
Author

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

B. Stinson
Greenhorn

Joined: Jan 03, 2011
Posts: 2
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Hi Stinson,
Welcome to javaranch.
Check the OpenSessionInView pattern.


If you are not laughing at yourself, then you just didn't get the joke.
B. Stinson
Greenhorn

Joined: Jan 03, 2011
Posts: 2
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a (widely) accepted architecture regarding the use of Hibernate?