cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Re: Hibernate sessions (was Re: [vote results] FOM)
Date Wed, 18 Jun 2003 11:25:24 GMT

On Wednesday, June 18, 2003, at 10:53 AM, Ugo Cei wrote:

> Jeremy Quinn wrote:
>> I open a new Hibernate Session at Function invocation, closing it on 
>> exit.
>
> FWIW, I've used this pattern in the past and it caused me some 
> problems. In particular, you risk leaving a session open whenever the 
> user does not complete the form submission.
>
> In my latest project, I've started using the "Open session in view" 
> pattern (http://hibernate.bluemars.net/43.html) and found it to be 
> much easier and robust.

Thanks for your advice!!!

I had been thinking about this as I am in the process of adding 
transactions etc to my code.

Because (I just realised) the Session has to be thrown away if there is 
any kind of Hibernate Exception, I was beginning to realise the only 
way of handling that safely was to wrap each call to Hibernate with a 
new Session.

So thanks for the confirmation ;)

The problem I still have to face is that I have to use 'lazy 
initialisation' as I am editing trees of objects with child/parent 
relationships, and I don't want the whole database loaded at once ;)
The problem is that if you try to access a Bean property that is not 
initialised (because it is lazy), while the Session is closed, you run 
the risk of getting a LazyInitializationException.

The obvious time to close the Session is when you are ready to send a 
page, but it is after you have sent the page (from FlowScript) that 
access to the Bean properties from JXForm takes place.

regards Jeremy


Mime
View raw message