You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andrey Tkach <tk...@sac.com.ua> on 2005/12/28 09:45:12 UTC

Tapestry 3.0.3 + hibernate extended session pattern

Hello,


I use Tapestry 3.0.3 + hibernate extended Session pattern described here
http://hibernate.org/43.html. Everything goes ok until session is not
invalidated first time (both by application server or by direct calling of
invalidate() method)


If application server perform httpSession.invalidate() at the method
doFilter from class HibernateThreadExtendedFilter on 'finally' section
marked line throws exception:

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
conversation has been started. Here is my log. I've done
httpSession.invalidate() (logout in my app), then I try to login again.

==============================================================start
log====================================================

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(GenericDAO
Hibernate.java:106)

      at
company.name.app.dao.hibernate.GenericDAOHibernate.findAll(GenericDAOHiberna
te.java:77)

==============================================================finish
log====================================================

 

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


Re: Tapestry 3.0.3 + hibernate extended session pattern

Posted by Michael Echerer <me...@tngtech.com>.
Andrey Tkach wrote:
> Hello,
Hi!
> 
> 
> I use Tapestry 3.0.3 + hibernate extended Session pattern described here
> http://hibernate.org/43.html. Everything goes ok until session is not
> invalidated first time (both by application server or by direct calling of
> invalidate() method)
As you explained already, you cannot remove the attribute from the
session as the session is already gone at that time.
Hence you could try to do the cleanup work while the session is going to
be destroyed. Therefore servlet context listeners are defined in the
servlet spec. You'll get a callback just when the session is going to be
destroyed. Depending on what servlet spec conform container you have
(2.3. vs. 2.4.) you could even try to manage this event based.

Have a look here for some ideas & the servlet spec:
http://www.javaworld.com/javaworld/jw-03-2003/jw-0328-servlet-p3.html
Cheers, Michael

> 
> 
> If application server perform httpSession.invalidate() at the method
> doFilter from class HibernateThreadExtendedFilter on 'finally' section
> marked line throws exception:
> 
> 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
> conversation has been started. Here is my log. I've done
> httpSession.invalidate() (logout in my app), then I try to login again.
> 
> ==============================================================start
> log====================================================
> 
> 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(GenericDAO
> Hibernate.java:106)
> 
>       at
> company.name.app.dao.hibernate.GenericDAOHibernate.findAll(GenericDAOHiberna
> te.java:77)
> 
> ==============================================================finish
> log====================================================
> 
>  
> 
> 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
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org