Solution :
I like answering questions based on spring + hibernate so I am trying to help you in fixing your mentioned error.
I had also faced the same issue in the past it was in the class which was not the part of any service layer. My transaction manager was very easily obtained from a context by my getBean()
method and also my class belonged to a view layer and the project was utilizing the OpenSessionInView
technique.
In my case my sessionFactory.getCurrentSession()
method was causing the same exception as yours. And solution for it is very simple as given below for your reference.
Session session;
try {
mysession = sessionFactory.getCurrentSession();
} catch (HibernateException mye) {
mysession = sessionFactory.openSession();
}
If by any chance the getCurrentSession()
method fails for you then the openSession()
should do the work for you..