34 lines
859 B
Java
34 lines
859 B
Java
package com.rosetta.im.database;
|
|
|
|
import org.hibernate.Session;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.cfg.Configuration;
|
|
|
|
public class HibernateUtil {
|
|
private static final SessionFactory sessionFactory;
|
|
|
|
static {
|
|
try {
|
|
sessionFactory = new Configuration().configure().buildSessionFactory();
|
|
} catch (Exception e) {
|
|
throw new ExceptionInInitializerError("Error initializing Hibernate: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public static SessionFactory getSessionFactory() {
|
|
return sessionFactory;
|
|
}
|
|
|
|
public static Session getCurrentSession() {
|
|
return sessionFactory.getCurrentSession();
|
|
}
|
|
|
|
public static Session openSession() {
|
|
return sessionFactory.openSession();
|
|
}
|
|
|
|
public static void shutdown() {
|
|
sessionFactory.close();
|
|
}
|
|
}
|