cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriele Columbro <colum...@gmail.com>
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]).

HTH,
Gabriele

PS.
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.


[1] http://cocoondev.org/main/117/43.html?layoutType=plain
[2] http://agylen.com/wp-content/Ugo_Cei_ApacheCon_2005EU.pdf
[3] http://www.springframework.org/docs/wiki/Spring_AOP_with_Hibernate.html
[4] http://www.nabble.com/Flow-and-hibernate-sessions-t1232967.html

Andre Juffer ha scritto:

> Joseph,
>
> you could have a look at:
>
> http://www.hibernate.org/42.html (especially 
> http://www.hibernate.org/42.html#A11)
>
> http://www.hibernate.org/43.html
>
> The SessionFactory is created only once in an interceptor 
> (http://www.hibernate.org/43.html#A3) 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: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>
>


-- 
Gabriele Columbro
Consultant at Sourcesense Italy
--
email:  columbro@gmail.com
blog:   http://www.mindthegab.com
mobile: (0039)3201612846
yahoo:  g.columbro
gtalk:  columbro@gmail.com
AIM:    gabrielecolumbro
--
"Keyboard not found. Press F1 to continue"
--


Mime
View raw message