> -----Original Message-----
> From: Richard Wallace [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, August 31, 2005 2:38 PM
> To: MyFaces Discussion
> Subject: Re: JSF + Spring + Hibernate
> 
> I do use OpenSessionInView for lazily loading objects in the 
> same request.  The problem that I've been running into is 
> when objects loaded from Hibernate have lazily loaded 
> collections and are put into the session before the 
> collection gets used.  Then on a future request, Hibernate 
> tries to lazily load the objects and can't because the 
> session used to retrieved them has been closed. 

The scope of the Hibernate session must match the scope of any lazily loaded
objects or collections.  That's one of the rules of Hibernate (or any other
ORM that I've used, for that matter).  Putting a proxy object in web session
scope while the Hibernate session is in request scope breaks that rule.  You
need to either use a transfer object, or cause Hibernate to initialize the
proxy by either setting the lazy attribute to false, or using
Hibernate.initialize().   You can also re-associate the object with the
Hibernate session as was mentioned before.

[EMAIL PROTECTED]



Reply via email to