
jpaoletti.jpm.hibernate.HibernateUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpm-hibernate Show documentation
Show all versions of jpm-hibernate Show documentation
Hibernate implementation of jpm data access.
The newest version!
package jpaoletti.jpm.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Hibernate Utility class with a convenient method to get Session Factory object.
*
* @author jpaoletti
*/
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession(){
return getSessionFactory().openSession();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy