1. This is exactely what HibernateDaoSupport / HibernateTemplate are for!!!
1.1 logger
private Log log = LogFactory.getLog(getClass());
HibernateDaoSupport already has a logger that logs messages for current class, you do not need to use a new one.
1.2 session initialisation
public Session openSession() {
return SessionFactoryUtils.getSession(getSessionFactory() , false);
}
This is not necessary, you need to inject the HibernateSessionFactory into your DAO using Spring IoC and then use
Code:
getHibernateTemplate()
Spring will take care of Hibernate Session initialisation.
1.3 "base" methods
public Object get(Class entityClass, Serializable id) throws DataAccessException {
Session session = openSession();
try {
return session.get(entityClass, id);
}catch (HibernateException ex) {
throw SessionFactoryUtils.convertHibernateAccessExceptio n(ex);
}
}
.........
All of those methods are already taken care of by HibernateTemplate. Please review the javadoc.
2. DAO implementations
Basically, you should not pass the Entity.class as a parameter to a DAO that manages the Entity class!!! You should instead create higher level method that manage the Entity instances using some primary keys / criteria. In some cases, you can add specific data validation into the Dao layer so as it can be reusable by higher level layers (services).
3. idem
4. other BusinessService extends EntityManager (idem)
When calling a ProductManger from a web controller to get a specific product you will use
Code:
Product product = (Product) productManager.get(Product.class, new Long(123));
I really prefer this version:
Code:
Product product = productManager.get(new Long(123));
less verbose, more specialized and no casting!!!!
HTH