I am not explicitly opening or closing sessions. I just use getHibernateTemplate(). I think Spring opens and closes session for every method call.
A typical method in my DAO would look like:
Code:
public void saveEntities(final List<Entity> entities) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws net.sf.hibernate.HibernateException, java.sql.SQLException {
for (Entity entity : entities) {
session.saveOrUpdate(entity);
}
return null;
}
});
}
I am interested in reusing the same session object across multiple doInHibernate() calls.
I also tried using a HibernateTemplate object as a instance variable in my DAO and use the instance variable (and hence the same template) to carry out multiple methods; that didnt seem to help either. A new session is used in every method call.