In such cases, implement a HibernateCallback, and execute it with HibernateTemplate's generic execute method. You can do anything you like with the Hibernate Session there, still properly participating in Spring's resource and transaction management. You do not need to close the Session in a finally block or the like: HibernateTemplate will do this for you.
Code:
Object result = hibernateTemplate.execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
...
return ...;
}
}
);
Juergen