Implementing DAOs with spring and hibernate
As I go through and implement my DAOs, I noticed that the generic DAO defined by the hibernate site and in books is a good design and has features that I like. However, Spring recommends the use of HibernateTemplate to get uniform exceptions thrown regardless of the underlying data access mechanism. I like that as well. The problem is that when combined with my long conversations (see a previous blog), it all gets quite messy. However, one option that allows me to write non-HibernateTemplate based DAOs is where you can annotate the DAO with a @Repository attribute then place the following definition in your application contexts where the DAO is defined: <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> If you have a hierarchical set of app contexts, the above bean definition must be placed in each bean definition. The only issue is whether the DAO needs to keep the session state or not. If so, the the DAOs cannot be used acr...