Hi, I found what causing it.
public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); }
return session; } It was the above ThreadLocal Session instance (in getSession() method)and Tomcat’s threading. Apparently Tomcat uses the thread pool and it will try to reuse the old threads. Some of my sessions are not closed and they are being attached to these threads.
So when old thread is being reused it shows the old value.
Solution:
public static void closeSession() throws HibernateException { Session session = (Session) threadLocal.get(); threadLocal.set(null);
if (session != null) { session.close(); } }
Since we are using struts 2, I created an interceptor and called the above closeSession() method to close all the sessions.
If your not using struts 2, but you got Servlet, use the Servlet chaining to accomplish above.
Good luck. Regards Raj
|