title: Upgrading to Hibernate 4.1 and the "infamous" HibernateTemplate
body: <p>I'm upgrading our project from Hibernate 3.0 to Hibernate 4.1.6. (And we are currently using spring 3.1)</p>
  
  <p>I read in many articles and in HibernateTemplate documentation, that since version 4.0 HibernateTemplate is not supported and that I should replace it's usage with calling <code>sessionFactory.getCurrentSession()</code> to get a session.</p>
  
  <p>Since this project was started with older version of Hibernate, where the use of <code>HibernateTemplate</code> was encouraged, we currently have 124 usages of <code>HibernateTemplate</code> across our project. I'm afraid that replacing all these occurrences with <code>sessionFactory.getCurrentSession()</code> might insert regression bugs in our project. In addition, there are some places where <code>HibernateTemplate</code> was used in a non-transactional context, where there is no 'current' session. What should I do in those cases? Open a new session and handle (close) it myself? That wasn't the case when I used <code>HibernateTemplate</code>.</p>
  
  <p>Do you have some good strategy addressing these issues?</p>
  
  <p>Thanks.</p>
  
  <p>Relevant reading:</p>
  
  <ol>
  <li><a href="http://jroller.com/kimchy/entry/hibernate_vs_spring_hibernate_template" rel="noreferrer">Hibernate Vs. Spring - HibernateTemplate history</a></li>
  <li><a href="https://community.jboss.org/wiki/HibernateCoreMigrationGuide40" rel="noreferrer">Hibernate Core Migration Guide</a></li>
  <li><a href="http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/" rel="noreferrer">MIGRATING TO SPRING 3.1 AND HIBERNATE 4.1</a></li>
  <li><a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/HibernateTemplate.html" rel="noreferrer">org.springframework.orm.hibernate3.HibernateTemplate</a></li>
  </ol>