Hibernate is, by default, very, very lazy about loading object
graphs. It'll load the "head" of the graph but generally nothing else until
you reference it.

        In a web app, this leads to two common sources of error:

        Cross threading:

        1) We load the "head" object and put it in cache (like the session)
in thread A.

        2) Later, thread B handles the same user's request, pulls the object
out of cache (the session) and tries to reference a sub-object. Boom.

        Closed Sessions:

        1) You open a session at the beginning of your transaction.
        2) You load an object and put it in the session.
        3) You complete the transaction.
        4) You close the session.
        5) New transaction starts (user clicks something else).
        6) New session created.
        7) Object comes out of session (still associated with original,
closed session).
        8) Reference a subobject. Boom.

        I *suspect* you're running into one of these tow problems.

        --- Pat
        

> -----Original Message-----
> From: Chris Chiappone [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 28, 2005 12:52 PM
> To: Tapestry List
> Subject: Tapestry and Hibernate
> 
> I have been developing an application using tapestry 3.0.3 and
> hibernate 3.0.2.  Took a while to get everything working correctly,
> and learning both of the frameworks.  I have a decent amount of the
> application written and now am running into
> LazyInitializationException in certain places.  Its strange because I
> can't expain why I get the exception and other times I don't.
> 
> I've read that using the Spring Framework would fix this problem, but
> wonder if its worth learning another framework and trying to integrate
> it into my application.  I'm on a deadline and this may just take to
> long.  I've also extended BaseEngine to do this trying to relieve my
> problem:
> 
> 
>         protected void cleanupAfterRequest(IRequestCycle cycle) {
>                 try {
> 
>                         HibernateUtil.commitTransaction();
> 
>                         if (killSession) {
>                                 try {
>                                         HttpSession session =
> cycle.getRequestContext()
>                                                         .getSession();
> 
>                                         if (session != null) {
>                                                 log.info("Logging out
> user.");
>                                                 session.invalidate();
>                                         }
>                                 } catch (IllegalStateException ex) {
>                                         // Ignore.
>                                 }
> 
>                         }
>                 } catch (NestedRuntimeException nre) {
> 
>                 } finally {
>                         HibernateUtil.closeSession();
>                 }
>         }
> Yet I still run into this exception:
> 
> Unable to resolve expression 'currentCompany.name' for
> [EMAIL PROTECTED]
> binding: ExpressionBinding[EditProfile currentCompany.name]
> location: context:/WEB-INF/EditProfile.page, line 41, column 65
> 
> ognl.OgnlException
> name
> 
> org.hibernate.LazyInitializationException
> could not initialize proxy - the owning Session was closed
> messages: [Ljava.lang.String;@cdf872
> throwableCount: 1
> throwables: [Ljava.lang.Throwable;@7227a8
> Stack Trace:
> org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitial
> izer.java:53)
> org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazy
> Initializer.java:84)
> org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.ja
> va:134)
> domain.company.Company$$EnhancerByCGLIB$$f029e618.getName(<generated>)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 39)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm
> pl.java:25)
> java.lang.reflect.Method.invoke(Method.java:585)
> 
> 
> Is there anything else I should try.  Or is the spring framework the
> way to go.  If so is it easy to integrate into an existing
> applicatoin?  Thanks.
> --
> ~chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to