加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Hibernate 4.0中的HibernateDaoSupport

发布时间:2020-12-15 01:38:03 所属栏目:大数据 来源:网络整理
导读:我是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 im

我是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 List

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读