java – Hibernate 4.0中的HibernateDaoSupport

前端之家收集整理的这篇文章主要介绍了java – Hibernate 4.0中的HibernateDaoSupport前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我是jsf 2.0 spring 3.1和hibernate 4.1集成的新手.如何更改以下代码,因为hibernate 4.0不包含HibernateDaoSupport.

  1. import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
  2. public class CustomerDaoImpl extends
  3. HibernateDaoSupport implements CustomerDao{
  4. public void addCustomer(Customer customer){
  5. customer.setCreatedDate(new Date());
  6. getHibernateTemplate().save(customer);
  7. }
  8. public List

我正在尝试这个样本:http://www.mkyong.com/jsf2/jsf-2-0-spring-hibernate-integration-example/

最佳答案
我找到了解决方案.我应该使用会话工厂.

  1. import java.util.List;
  2. import org.hibernate.SessionFactory;
  3. public class CustomerDaoImpl implements CustomerDao{
  4. private SessionFactory sessionFactory;
  5. public SessionFactory getSessionFactory() {
  6. return sessionFactory;}
  7. public void setSessionFactory(SessionFactory sessionFactory) {
  8. this.sessionFactory = sessionFactory;
  9. }
  10. public void addCustomer(Customer customer){
  11. getSessionFactory().getCurrentSession().save(customer);
  12. }
  13. public List

猜你在找的Spring相关文章