微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Hibernate 4.0中的HibernateDaoSupport

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

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


    public class CustomerDaoImpl extends 
           HibernateDaoSupport implements CustomerDao{

        public void addCustomer(Customer customer){

            customer.setCreatedDate(new Date());
            getHibernateTemplate().save(customer);

        }

        public List

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

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

import java.util.List;

import org.hibernate.SessionFactory;

public class CustomerDaoImpl implements CustomerDao{
    private SessionFactory sessionFactory;
    public SessionFactory getSessionFactory() {
        return sessionFactory;}
    public void setSessionFactory(SessionFactory sessionFactory) {
         this.sessionFactory = sessionFactory;
    }

    public void addCustomer(Customer customer){


        getSessionFactory().getCurrentSession().save(customer);

    }

    public Listcreatequery("from Customer").list();
        return list;

    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐