Spring: Why the SessionFactoryUtils class in Hibernate 4 does not provide the getSession method?

gastaldi picture gastaldi · Feb 8, 2012 · Viewed 9.7k times · Source

What happened to the SessionFactoryUtils.getSession method from Hibernate 4 in Spring 3.1.0 ? What should be used instead ? sessionFactory.getCurrentSession() keeps giving me this exception:

org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:883)

Any hint ?

Answer

ianpojman picture ianpojman · May 2, 2012

Use sessionFactory.getCurrentSession()

I believe the concept of a "current session" came in Hibernate 3, SessionFactoryUtil was written before this existed.