-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Connection still alive
PostPosted: Fri Jun 16, 2006 6:37 am 
Newbie

Joined: Tue Jun 13, 2006 11:33 am
Posts: 6
Location: Paris
I have a J2EE application with tomcat, hibernate 3 and Postgresql.
This application needs to get data from several databases (BVM,CS,CRM). As it is explained in the hibernate guide, I have a HibernateUtil managing the sessions :

Code:
public class HibernateUtil {
      
     private static final SessionFactory bvmSessionFactory;
     private static final SessionFactory crmSessionFactory;
     private static final SessionFactory csSessionFactory;
    
      static {
         
         try {
          String pathFile = "WEB-INF/config/bvm.cfg.xml";
          if(!(System.getProperty("bvm.cfg.xml")==null)){
              pathFile = System.getProperty("bvm.cfg.xml");
          }
           File bvmFile = new File(pathFile);
           bvmSessionFactory = new Configuration().configure(bvmFile).buildSessionFactory();
          
          
           pathFile="WEB-INF/config/crm.cfg.xml";
           if(!(System.getProperty("crm.cfg.xml")==null)){
              pathFile=System.getProperty("crm.cfg.xml");
           }     
           File crmFile = new File(pathFile);
           crmSessionFactory = new Configuration().configure(crmFile).buildSessionFactory();
                
          
           pathFile="WEB-INF/config/cs.cfg.xml";
           if(!(System.getProperty("cs.cfg.xml")==null)){
               pathFile=System.getProperty("cs.cfg.xml");
            }
            File csFile = new File(pathFile);
            csSessionFactory = new Configuration().configure(csFile).buildSessionFactory();
            
         } catch (HibernateException ex) {
            throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
         }
      }

      public static final ThreadLocal bvmSession = new ThreadLocal();
      public static final ThreadLocal crmSession = new ThreadLocal();
      public static final ThreadLocal csSession = new ThreadLocal();

      public static Session getBvmSession() throws HibernateException {
         Session s = (Session) bvmSession.get();
         // Open a new Session, if this Thread has none yet
         if (s == null) {
            s = bvmSessionFactory.openSession();
            bvmSession.set(s);
         }
         return s;
      }

      public static void closeBvmSession() throws HibernateException {
         Session s = (Session) bvmSession.get();
         bvmSession.set(null);
         if (s != null){
            s.close();
        
         }
      }
      
      public static Session getCrmSession() throws HibernateException {
            Session s = (Session) crmSession.get();
            // Open a new Session, if this Thread has none yet
            if (s == null) {
               s = crmSessionFactory.openSession();
               crmSession.set(s);
            }
            return s;
         }

         public static void closeCrmSession() throws HibernateException {
            Session s = (Session) crmSession.get();
            crmSession.set(null);
            if (s != null){
               s.close();
               s=null;
            }
         }
         
         
         
         public static Session getCsSession() throws HibernateException {
               Session s = (Session) csSession.get();
               // Open a new Session, if this Thread has none yet
               if (s == null) {
                  s = csSessionFactory.openSession();
                  csSession.set(s);
               }
               return s;
            }

            public static void closeCsSession() throws HibernateException {
               Session s = (Session) csSession.get();
               csSession.set(null);
               if (s != null){
                  s.close();
                  s=null;
               }
            }

   }


Problem is that I have more and more postgresql processes which are not finished until tomcat is shutdown (all process killed by the end of the jvm) so I have a java heap space error.

If someone could give me a piece of advice it would be great.[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.