cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriele Columbro <>
Subject Re: Hibernate+Flow+Cocoon?
Date Fri, 06 Oct 2006 13:18:16 GMT
Hi Joseph,
a very well established best practice in using cocoon flow (flowscript 
or javaflow) with Hibernate is the so-called CHS 
(Cocoon-Hibernate-Spring) approach first introduced here [1]. Of course 
it requires for your project to rely/depend also on Spring, but I think 
that this can only be a plus, also because of the very recent release of 
Spring 2.0.
As properly described here [2] (these slides were presented both in 
Cocoon GetTogheter and ApacheCon) you should:

1. Declare your persistence objects (Hibernate persistence manager, 
datasource and DAO) in the spring applicationContext
2. Load the context via contextListener in the web.xml
3. Load your (transactionally wrapped) service via flow using a Spring 
facility and load/use your services easily

Integrating Hibernate and Spring is probably the most common Spring 
usage scenario so you should find plenty of docs in the web (e.g. [3]).


Working with this approach may lead you to some problems while using 
continuations (and his request/response cycle wrapping) AND hibernate 
lazy loading, because of the premature closure of the session. If this 
is your case, to solve it you may have a look at this [4], where a 
HibernateFlowAdapter is provided.


Andre Juffer ha scritto:

> Joseph,
> you could have a look at:
> (especially 
> The SessionFactory is created only once in an interceptor 
> ( where also the transaction is 
> started and committed. I do not use flow to create the SessionFactory. 
> To access the session, I depend on the repository pattern where the 
> current session is obtained from the SessionFactory.
> Hope this helps,
> Andre
> Joseph Toman wrote:
>> I was wondering if anyone had advice or opinions on
>> using Hibernate+Flow+Cocoon? I'm writing a small test
>> application to understand the issues involved, and I'm
>> not quite clear where the SessionFactory should be created.
>> According to the Hibernate documentation it's a relatively expensive
>> operation, so I don't want to do it each time the flowscript runs.
>> Ideas, or things that have worked for you would be greatly appreciated.
>>                         J. Toman
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

Gabriele Columbro
Consultant at Sourcesense Italy
mobile: (0039)3201612846
yahoo:  g.columbro
AIM:    gabrielecolumbro
"Keyboard not found. Press F1 to continue"

View raw message