
tr.com.lucidcode.util.HibernateUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kite-framework Show documentation
Show all versions of kite-framework Show documentation
A Web Application Framework providing DRY use of rich UI components.
The newest version!
package tr.com.lucidcode.util;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import tr.com.lucidcode.config.HibernateConfiguration;
public class HibernateUtil {
protected static Logger logger = Logger.getLogger("hibernateUtil");
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
return new Configuration().configure().buildSessionFactory(HibernateConfiguration.hibernateConfig());
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
logger.error("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static void turnOn() {
logger.debug("turning on Hibernate session");
// Create Database connection
getSessionFactory().openSession();
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
logger.debug("shuting down Hibernate session");
// Close caches and connection pools
getSessionFactory().close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy