cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Lundquist>
Subject Re: Where to store a hibernate session in Flow?
Date Wed, 04 Aug 2004 18:54:41 GMT

On Aug 3, 2004, at 7:34 PM, Joel McConaughy wrote:

> Good to hear from you, Mark.

Likewise :-)

>  Actually, what I'd like to do is keep the session factory open during 
> the course of either the session or application context.  Then I can 
> just open and close sessions as needed -- hopefully providing a 
> performance improvement.  If there really isn't any way to get 
> notified when the session or application context get invalidated so I 
> can close the factory, then they are pretty useless IMO.

Why do you need to close the factory?  Just leave it open.

You might also look at implementing the Thread Local Session pattern 
(  I implement this pattern with 
a class called HibernateFactory, which wraps the session factory like 

     private static SessionFactory sf;

     private static SessionFactory getSessionFactory()
         throws Exception
         if (sf == null) {
             System.out.println ("Initializing HibernateFactory");
             try {
                 net.sf.hibernate.cfg.Configuration cfg;
                 cfg = new Configuration();
                 sf = cfg.buildSessionFactory();
             catch ( Exception e) {
                 System.err.println("Hibernate:" + e.getMessage());
         return sf;

Note that this method is private... nobody outside this class needs the 


View raw message