I am using Hibernate and Spring in my project. My DAO has several methods like
getEntity()
getRelatedEntities()
etc.
Since the related entities are loaded lazily, I want to reuse the session across multiple method calls. I want to make sure that getHibernateTemplate() in all the methods in my DAO use the same session instead of creating one for each method call. I have tried using "HibernateTransactionManager" with "LocalSessionFactory"; but whenever I make a call to the DAO, it throws an exception that says "no session is bound or session closed". Do I have to explicitly get a session in the DAO and bind it to the current
thread of DAO, so that the session is retained across all method calls in that DAO ?
Also, the use of SessionFactoryUtils.getSession() method is not very clear to me. When and where can it be used ?
Responses are much appreciated.