Hello,
I use hibernate extended Session pattern and everything goes ok until session is not invalidated first time both by application server or by direct calling invalidate();
If application server perform httpSession.invalidate() at the method doFilter from class HibernateThreadExtendedFilter on ‘finally’ section marked line throws exception:
Code:
finally {
log.error("Cleanup after exception!");
// Cleanup
log.debug("Closing and unbinding Session from thread");
sf.getCurrentSession().close(); // Unbind is automatic here
log.debug("Removing Session from HttpSession");
httpSession.setAttribute(HIBERNATE_SESSION_KEY, null); <<<<<<<<<<<<<<< removeAttribute: Can’t do it because session already invalidated!
}
// Let others handle it... maybe another interceptor for exceptions?
throw new ServletException(ex);
}
}
After that I have a trouble with restoring transaction even if new session has been started. Here is my log. I’ve done httpSession.invalidate() (logout in my app) then I try to log in again.
Quote:
135032 ERROR company.name.app.util.HibernateThreadExtendedFilter : removeAttribute: Session already invalidated <<<< finally section after logout
450344 DEBUG company.name.app.util.HibernateThreadExtendedFilter : >>> New conversation <<< try to log in again.
450344 DEBUG company.name.app.util.HibernateThreadExtendedFilter : Starting a database transaction
450344 DEBUG company.name.app.util.ExtendedThreadLocalSessionContext : Opening a new Session
450344 DEBUG company.name.app.util.ExtendedThreadLocalSessionContext : Disabling automatic flushing of the Session
450407 DEBUG company.name.app.util.HibernateThreadExtendedFilter : Committing database transaction
450407 DEBUG company.name.app.util.HibernateThreadExtendedFilter : Unbinding Session from thread
450407 DEBUG company.name.app.util.HibernateThreadExtendedFilter : Storing Session in the HttpSession
450407 DEBUG company.name.app.util.HibernateThreadExtendedFilter : > Returning to user in conversation
468985 DEBUG company.name.app.util.HibernateThreadExtendedFilter : < Continuing conversation
468985 DEBUG company.name.app.util.HibernateThreadExtendedFilter : Starting a database transaction
org.hibernate.HibernateException: createCriteria is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:289)
at $Proxy0.createCriteria(Unknown Source)
at company.name.app.dao.hibernate.GenericDAOHibernate.findByCriteria(GenericDAOHibernate.java:106)
at company.name.app.dao.hibernate.GenericDAOHibernate.findAll(GenericDAOHibernate.java:77)
Could somebody tell me what might be the reason of such application behavior? Is it possible to make transaction restore with the session?
Thanks in advance,
Andrey