Hello i have some doubts about if i m using correctly hibernate. I have created the typical HiibernateUtil for managing the Session. My problem resides that im using AOP for controlling transactions, so before calling the method, first i get the session from ThreadLocal of HibernateUtil and i start the transaction, after all operations inside this transaction has been executed, i make a commit and finally a session.close().
What is my surprise that when i try to use in next operation the hibernate, that my Interceptor throws an exception telling me that session is closed. I just don't understand why happens that thing, because the code is the same like has been called first time. For now, always the session is open (like long conversations approach.
Can anybody tell me if i m OK. In fact caveatemptor example used the last thing i have explain it, opening session one time only and always returning the session of threadlocal. My Interceptor is a copy of its filter and my HibernateUtil is like its application.
Im using Hibernate 3.1 with annotations.
Code:
public static Session currentSession() throws HibernateException {
Session s = session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
Thank you very much if anybody can clarify to me this doubt.