HibernateTemplate vs HibernateDaoSupport vs SessionFactory Injection

后端 未结 3 1903
既然无缘
既然无缘 2021-02-03 15:27

I have seen in lot of forums and still in confusion. We are starting a new project with Spring 3.1 & Hibernate 4 and need to decide which strategy to use for Hibernate with

相关标签:
3条回答
  • 2021-02-03 15:57

    If you must use Hibernate, your best bet is to ignore Code Ranch (and SO) and follow the recommendation from Spring:

    http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

    0 讨论(0)
  • 2021-02-03 16:09

    Now SessionFactory is recomended for Hibernate 4 for open/close connection automatically. So no need to use HibernateTemplate class.

    0 讨论(0)
  • 2021-02-03 16:11

    Spring itself recommends not using HibernateTemplate anymore, in the javadoc of the class. You can declare the session factory as a Spring bean directly, inject it as any other Spring bean in your own components, and use the native Hibernate API directly (using sessionFactory.getCurrentSession()).

    0 讨论(0)
提交回复
热议问题