This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
Welcome to javaranch.
Check the OpenSessionInView pattern.
If you are not laughing at yourself, then you just didn't get the joke.
Joined: Jan 03, 2011
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Is there a (widely) accepted architecture regarding the use of Hibernate?