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: Flow Database stuff ( The new FOM? )
Date Fri, 11 Jul 2003 18:37:34 GMT

On Friday, July 11, 2003, at 05:45 PM, Reinhard Pötz wrote:

>
> From: Jeremy Quinn
>
>> The problem arises when you wish to use a (brilliant) feature of
>> Hibernate called 'lazy-initialisation', whereby access to the DB is
>> only made when you actually ask for Bean Properties.
>>
>> This is particularly useful when you have large 'graphs' of related
>> Beans, for instance child/parent relationships, whereby loading one
>> Bean may result in the whole database loading!!
>>
>> If you have closed your Hibernate Session in your Flowscript, your
>> display layer can throw LazyInitialisationExceptions, because the
>> connection is no longer available.
>>
>> Not closing the Session after you have sent the Response, is
>> considered
>> bad practise, so the Servlet Filter is a handy solution.
>
> It's a pity that Hibernate is under LGPL - this would be a great 
> example
> ...
> Have the Hibernate people ever been asked if they would put their
> great piece of software under a more Apache like licence?

Yes, they have been asked on numerous occasions, last time I noticed by 
Hugo Burm (a cocoon regular), they are obviously pretty sick of being 
asked because they can get pretty rude about it ....

They are firmly of the opinion that LGPL does not prevent Hibernate 
being used by other projects, which is something I know this forum 
strongly disagrees with.

I have not wanted to wade into that discussion with them TBH, I have 
not found them to be a particularly friendly community.

They have several Apache jars in their dist, so I find it pretty 
objectionable that the reverse cannot be accomplished!

> As I'm curious I have a technical question:
> What's the difference if I read the necessary data in the flow or some
> milliseconds latter in the view layer? What do I gain?

By passing a Bean persisted by Hibernate from the flow layer to the 
view layer, you are implementing SoC by allowing the view layer to 
decide what is relevant for that view. This aspect not being the Flow's 
concern.

However, once you have triggered the view layer with SendPageAndWait(), 
control does not return to the flow layer until the Response has been 
sent and the next Request received, thus loosing you the opportunity to 
close the Hibernate Session from the Flow layer before the Response is 
sent.

SendPage() might not suffer this problem, but due to the nature of a 
SAX event pipeline, I would not bet on it.

With 'lazy initialisation' SQL Queries are only made when getter 
methods of the Bean are executed. If you have passed the Bean to the 
view layer, XPath expressions in JXPathTemplate (etc.) will result in 
those getter methods being accessed. If your flowscript has already 
released it's Hibernate Component, you are in trouble.

You could clone the Bean to pass it to the view layer, but it is kind 
of self-defeating IMHO.

>>>> However, with the generous assistance of Ugo Cei, I am
>> successfully
>>>> using the technique highlighted in the first sample here [1] for
>>>> managing Hibernate Sessions in my FlowApp.
>>>>
>>>> The basic issue is that you want to avoid maintaining an open
>>>> Hibernate Session whilst the user is interacting with a
>> form (etc.).
>>>> The Session
>>>> should to be opened and closed during each Request (and any
>>>> Transient
>>>> Beans refreshed before re-use). The above technique uses a Servlet
>>>> Filter to manage this, with a static method to retrieve a
>> Session in
>>>> your flowscript at the beginning of each Request that needs it.
>>>>
>>>> [1] http://hibernate.bluemars.net/43.html
>>>>
>>>
>>> Sounds cool and I remember that I've already heard from it
>> but haven't
>>> found the time to try it myself.
>>
>> I am using it ATM on a client project and it is a dream!
>>
>>> <dream-mode>
>>>  I would like to use this Avalon component mentioned above and  the
>>> Flow interpreter takes care of releasing (and providing)  stateful
>>> components within my scripts. So I would have to  lookup
>> the Hibernate
>>> Session at the beginning(2) and until I  finally release(8)
>> it I don't
>>> have to take care for it.
>>>
>>>  1  function xxx() {
>>>  2    var hibS = cocoon.getComponent( "hibernateSession" );
>>>  3    var custBean = hibS.blablabla // get your beans with hibernate
>>>  4    sendPageAndWait( "bla", {customer : custBean} );
>>>  5    // do something (updates, reads, whatever)
>>>  6    var someDifferentBean = hibS.blalbalba
>>>  7    sendPageAndWait( "bla", {diff : someDifferentBean } );
>>>  8    sendPageAndRelease( "thankYou", {} );
>>>  9  }
>>>
>>>  This would be IMO a very elegant way and IIU the recent
>> discussion
>>> correctly possible from a technical point of view. Maybe Chris  can
>>> comment on this :-)
>>>
>>>  Thoughts?
>>
>> This is a reality!
>> Wake up and smell the toast ;)
>
> ;-)
>
>>
>> I just do not use the Component Manager, because I cannot manage the
>> Hibernate Session entirely from the FlowScript layer as explained
>> above. I have a static method that gives me a fresh Session. I get s
>> Session at the beginning of  Function, or directly after a
>> sendPageAndWait().
>
> Is it possible to have a look at the sources? I would be very
> interested!


I don't have any really clear examples to show you right now (I have 
tried to extract some but I am not happy with them, I am also not very 
happy NOT sending something ;), but I was thinking of making a sample 
'User Editor' as a contribution to the wiki, once my work-rush is over 
....

regards Jeremy

Mime
View raw message