If you don´t want to use Spring, you could create your session factory
as an avalon component and configure it in the cocoon.xconf file so it
gets launched as a cocoon component, wich can be accessed from flow
with a cocoon.getComponent() call. It's been a long time since i did
it, so i don´t remember the specifics, but it should work.

Anyway, doing it in spring is easier/faster, so check it out. I did,
and It's great.


On 10/6/06, Gabriele Columbro <[EMAIL PROTECTED]> wrote:
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: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>


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



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to