My question is about best practices for using Hibernate in Java applications and the DAO pattern.
I jumped into a project that had some classes that another developer generated using Middlegen (MG). So, we have a DB and a mapping between DB tables and Java classes using Hibernate. What I want to know is: What else do I need to write in order to implement the DAO pattern? With just the MG generated classes, I find myself scattering Session related stuff all over my app in order to make sure collections are loaded (since we want lazy-loading) before I reference them.
Also, anytime I need to find a database object, I have to create Hibernate Criteria or Query objects. Should I instead write find() methods for each of the MG generated classes?
In order to properly implement the DAO pattern, should I have the MG classes implement DAO interfaces. In other words, if I have a 'book' table in my DB, should I write a Book interface and have MG generate a HibernateBookImpl class?
Any design help would be greatly appreciated. My main goal is to allow for lazy-loading of collections references without having any business layer code know anything about Hibernate or lazy-loading.
|