I never detach the object from the session - so the sequence is like this
(starting with a fresh session):

   1. Request: -make new Hibernate session
               -get all X from Database, 
               -render list of X
               -disconnect hib-session from DB and store it in http-Session
(X's are NOT detached here).
   
    2. Request - lookup user's http session, get his hib-session
               - reconnect hib-session to Datasource
               - load collection X.allMyYs for some X lazily (no Problem,
the X's are still attached)
                   - render allMyYs 
                   - as 1. Request

For me, I *really* started to enjoy Hibernate only after I switching to the
long session pattern. 

Marcus


> -----Original Message-----
> From: Pablo Ruggia [mailto:[EMAIL PROTECTED]
> Sent: Thursday, May 19, 2005 2:25 PM
> To: Tapestry users
> Subject: Re: Hibernate + Spring: LazyInitializationException
> 
> 
> And what happens if you need to access a Collection in a second
> request from user. How it works if you do not reattach the object ?
> 
> On 5/19/05, Schulte Marcus <[EMAIL PROTECTED]> wrote:
> > I'm using the long session pattern put forward in HIA by 
> Bauer&King. This
> > works very well - no LazyInitializationException nor
> > NonUniqueObjectExceptions when re-attaching objects. In fact, no
> > re-attaching at all.
> > The recipe is:
> >   1. ServletFilter to manage mapping of Http-Sessions to 
> Hibernate-Sessions
> > and putting the latter in a convenient ThreadLocal
> >   2. An IActionListener-Wrapper to commit/rollback as desired
> >   3. Not forgetting to close your Session and throw away 
> your persistent
> > objects at an appropriate point (typically, this is "user choses new
> > working-set" or somethin like that)
> > Only "drawback" - the pattern is not supported by any 
> IoC-Containers out of
> > the box - at least by none I know of.
> > If anybody is interested I could post some code ...
> > 
> > Marcus
> > 
> > 
> ---------------------------------------------------------------------
> > 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]
> 

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

Reply via email to