-->
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: Hibernate Out of Memory
PostPosted: Thu Nov 22, 2007 9:23 am 
Newbie

Joined: Mon Jun 04, 2007 7:43 am
Posts: 1
Hi,

I'm using hibernate, it works very well but I think I'm doing something wrong, but it's very slow.

While I'm using the memory is always increasing until I have an out of memory problem.

I really don't know why it occurs.

I have the follow singleton:


Code:
public class HibernateSessionCreator {
   
   public HibernateSessionCreator() {}
   
   public Session createSession() {
      HibernateSingleton hs = HibernateSingleton.instance();
      return hs.sessionFactory.openSession();
   }
}



Code:
class HibernateSingleton {
   
   private static HibernateSingleton instance;
   
   public SessionFactory sessionFactory;

   private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
   
   private HibernateSingleton() {
      Configuration cfg = new Configuration();
      cfg.configure(CONFIG_FILE_LOCATION);
      sessionFactory = cfg.buildSessionFactory();
   
      if (sessionFactory == null){
//         log.error("Could not create SessionFactory" );
         throw new RuntimeException("Could not create SessionFactory");
      }
   }
   
   public static synchronized HibernateSingleton instance() {
      if (instance == null) {
         instance = new HibernateSingleton();
      }
      return instance;
   }
}


And a simple get:

Code:

   public void update(Phase p) {
      Session session = new HibernateSessionCreator().createSession();
      
      try {
         session.beginTransaction();
         
         session.saveOrUpdate(p);
         
         session.getTransaction().commit();
      }catch(Exception ex) {
         System.err.print(ex.toString());
         session.getTransaction().rollback();
      }finally {      
         session.close();
      }
      
   }


any idea to solve the problem?

Thanks


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.