You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurent PETIT <lp...@sqli.com> on 2003/04/18 16:24:50 UTC

ORMs proxies and lazy initialisations issues in the view

Hello,

What do you think is the best approach for you to solve the problem written
in the subject ?

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.

"

With the Struts architecture, it appears to me that the 2d solution sounds
simpler, but it isn't quite satisfying, because it implies that the
controller or even the Session Facade to the data knows exactly what datas
the View layer will need for its purposes.

The first approach may be the best to me. The solution to implement with
this approach sounds like subclassing the RequestProcessor.

I searched in the API, and found a hook method : processPreprocess()

" General-purpose preprocessing hook that can be overridden as required by
subclasses. Return true if you want standard processing to continue, or
false if the response has already been completed. The default implementation
does nothing "

I think it may be the good place to, for example, start a data session
opening.

But what I would like to find then isn't present : something like
processPostProcess() method, called after the view has been rendered, where
I could flush() data session a last time, and then close().

What do you think about this ?

Do you know a third method ?

What would you suggest me to do ?

Thanks in advance,



--

Laurent PETIT.



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