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