You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/06/12 16:23:44 UTC

Re: ORMs proxies and lazy initialisations issues in the view

> For example, in the Hibernate FAQ, I've found this entry :
> "
> In an MVC application, how can we ensure that all proxies and lazy
> collections will be initialized when the view tries to access them?
> 1- One possible approach is to leave the session open (and transaction
> uncommitted) when forwarding to the view. The session/transaction would be
> closed/committed after the view is rendered in, for example, a servlet
> filter (another example would by to use the ModelLifetime.discard() callback
> in Maverick). One difficulty with this approach is making sure the
> session/transaction is closed/rolled back if an exception occurs rendering
> the view.
> 
> 2- Another approach is to simply force initialization of all needed objects
> using Hibernate.initialize(). This is often more straightforward than it
> sounds.
> 
> "

I believe there is a 3rd option not mentioned on the Hibernate FAQ
page that uses a Filter for this exact purpose.  I have found that
it is much simpler to use filters around struts then to try to
modify struts source code.  Here is the link:

http://hibernate.bluemars.net/43.html

Has anyone successfully gotten lazy initialization to work in struts without
having to resort to Hibernate.initialize(), because again, how would
we know what the view is going to use the data for.  The view might
do something like?

user.company.industries

When all we gave them was user...it would be very hard to initialize
all those paths.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"I am the GOD.....the GOD...of house!" 
 -- Leeloo
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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