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
A combination of skaffman's post and Sean's plus the use of annotations.
Dao
@Respository("productDao")
public class ProductDaoImpl implements ProductDao {
@Autowired
private SessionFactory sessionFactory;
public Collection loadProductsByCategory(String category) {
return this.sessionFactory.getCurrentSession()
.createQuery(
"from test.Product product where product.category=?")
.setParameter(0, category)
.list();
}
}
xml
product.hbm.xml
hibernate.dialect=org.hibernate.dialect.HSQLDialect