cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brent Johnson <>
Subject Re: Using Hibernate via Java, not Flow
Date Wed, 13 Apr 2005 23:02:17 GMT
Yeah this is exactly the problem I'm having. If I close the session and then 
call sendPageAndWait() I get the LazyInitializationException. So it's been 
difficult for me to decide exactly where I should close the session. But 
this is why I can't figure where to make the close call.

For example:

var isrunning = true;
while (isrunning) {
var myobject = MyWrapper.getTypes(); // this is a call that returns a POJO
cocoon.sendPageAndWait("whatever/temp.html", { "myobj" : myobject });
if (cocoon.request.get("submit") == "save") {
} else if (cocoon.request.get("submit") == "quit") {
isrunning = false;

Ok - I just made that up, but its similar to what I'm trying to do. With a 
sendPageAndWait in a loop where would you close the hibernate session? Can't 
do it before the sendPageAndWait or you'll get the LazyInitialization 
problems, can't close it afterwards because I need to possibly save the 
data. Can't do it after that because I'll probably loop and need to reload 
the data and start all over.

So where does it get closed? What happens if I skip the continuation, and do 
something like use the back button and go back to the same page and try to 
load the data? Since I aborted the continuation isnt there a session there 
open to the POJO objects? I dunno, I've been staring at this too long today 
:) I'll take a break and read your link about the Open-Session-in-View 


- Brent

On 4/13/05, JD Daniels <> wrote:
> I use the open Session in view model. The session lasts the duration of
> the request. I can't find the article I used to get up to speed on it,
> but this should get you going:
> Brent Johnson wrote:
> > Well, I tried adding in a hibernate close to get around the issue of two
> > different sessions monkeying around with the POJO objects, causing an
> > exception to be thrown (and when those get thrown the whole application
> > flakes out).
> >
> > But, I'm running into a "chicken-or-the-egg" problem. If I close the 
> session
> > prior to my sendPageAndWait() call, the POJO's become invalid and if I 
> try
> > to access one of their getters I get an exception:
> > could not initialize proxy - the owning Session was closed
> >
> > But, I can't close them right after the sendPageAndWait(), because at 
> that
> > point I need to decide whether I should save the modified POJO's, delete
> > them, etc depending on what the user chose to do.
> >
> > Where do most people decide to close their sessions when using
> > sendPageAndWait()?
> >
> > On 4/13/05, Leszek Gawron <> wrote:
> >
> >>It's all not that hard but still there's some philosophy to swallow and
> >>that might take time.
> >
> >
> >
> > I'm a pretty quick learner, I'll take a quick look and see if I can wrap 
> my
> > head around it enough to be able to get it implemented before the 
> project is
> > scheduled to start testing.
> >
> > Thanks,
> >
> > - Brent
> >
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View raw message