I’m still quite new to Spring, and I’ve found it to irritating making all these CRUD DAOs, so I’ve made a “public class GenericCRUDDAO extends HibernateDaoSupport implements CRUDDAO”. In my service objects I then simply say something like
private GenericCRUDDAO<User, Integer> userDAO = new GenericCRUDDAO<User, Integer>();
and no more do I have to write simple DAOs and wire them up. Yay! Except for one thing I’m sure all you experienced Spring developers see right away: I cannot get the Hibernate template inside the GenericCRUDDAO, so doing
HibernateTemplate ht = getHibernateTemplate();
gives me a ht that is null. Not so good. I thought of wiring it in, meaning making a genericCRUDDAO bean and then setting a static AnnotationSessionFactoryBean, but that still wouldn’t give me a HibernateTemplate. Any suggestions on how I work around that so that I can have my Hibernate Template?
Any more issues with making a generic CRUD DAO I should be thinking about?
Cheers
Nik
For many,
HibernateTemplateandHibernateDaoSupportare on the outs, and instead injecting aSessionFactoryis preferred. Not everyone, mind you, but it is a trend, which I adopted not too long ago, removingHibernateTemplatefrom my own generic DAO.This blog has a pretty good summary.
The author’s examples should be able to help you get to where you want to be.