I'm developing a JavaFX Hibernate desktop application. I configured my application so that I use the same session from the application runs till it close. This is how I did it:
public static Session getCurrentSession() {
if (sessionFactory != null) {
Session session = sessionFactory.getCurrentSession();
if (session != null) {
return sessionFactory.getCurrentSession();
} else {
session = sessionFactory.openSession();
session.beginTransaction();
return session;
}
}
return null;
}
And when the User close the App, I run a second method that closes the session and the SessionFactory.
public static void closeConnections() {
if (sessionFactory != null) {
if (sessionFactory.getCurrentSession().isOpen()) {
sessionFactory.getCurrentSession().close();
}
sessionFactory.close();
}
}
I'm newB on Hibernate so be kind with me PEACE