On Friday, July 11, 2003, at 03:13 PM, Reinhard Pötz wrote:



From: Jeremy Quinn


On Thursday, July 10, 2003, at 09:04 AM, Reinhard Pötz wrote:



IMO no. I would use Object/Relational mapping tools like OJB http://db.apache.org/ojb/ or Hibernate (http://hibernate.bluemars.net).


Is there a wiki somewhere on this type of thing?

http://wiki.cocoondev.org/ Wiki.jsp?page=XMLFormJXFormHibernateAndFlowscr ipt and here you find a component providing a Hibernate session: http://cvs.werken.com/viewcvs.cgi/plexus-components/hibernate /src/java/org/apache/plexus/hibernate/ DefaultHibernateService.java?cvsro ot=plexus


Forgive me if I have not entirely understood the usage patterns of the classes above.

IIUC this component provides a Hibernate Session. At the current FOM implementation you have to take care that you open and close these sessions correctly.

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.


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().


</dream-mode>

HTH


regards Jeremy



Reply via email to