hibernateTemplate HibernateDaoSupport不建议在Spring与Hibernate整合中使用

HibernateTemplate类属于spring框架中的类 :org.springframework.orm.hibernate3.HibernateTemplate

HibernateTemplate类目前Hibernate4不支持此类,只支持到Hibernate3,而且在SH整合过程中,如果DaoImpl采用Hibernate实现方法,如果采用Hibernate原声的SessionFactory,即使不采用Spring,原声的SessionFaction同样可以使用,将有利于Dao是可以移植性; 而若果采用HibernateTemplate,必须要有Hibernate和Spring的环境,这样将影响项目的移植性

HibernateDaoSuppert跟HibernateTemplate一样不建议使用,而且在Hibernate4 的时候已经被废除 

建议在SH的Dao中使用SessionFactory

package dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

pubilic  ...DaoImpl implement ...Dao{

  private SessionFactory sessionFactory;

  private Session getSession(){

    return sessionFactory.getCurrentSession();

  }

}

原文地址:https://www.cnblogs.com/a757956132/p/3892696.html