Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 599
gastaldi Avatar asked Feb 08 '12 12:02

gastaldi


1 Answers

Use sessionFactory.getCurrentSession()

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

like image 182
ianpojman Avatar answered Sep 23 '22 06:09

ianpojman