I am not sure whats the best way to inject Hibernate\'s session instance to DAO classes using Spring3. I am not using Spring\'s Hibernate Template support for this so here i
The Spring Reference suggests this usage:
public class ProductDaoImpl implements ProductDao {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Collection loadProductsByCategory(String category) {
return this.sessionFactory.getCurrentSession()
.createQuery(
"from test.Product product where product.category=?")
.setParameter(0, category)
.list();
}
}
That way your classes don't have any dependencies to Spring, you just use plain Hibernate.