package common;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
private static Configuration cfg;
private static SessionFactory sessionFactory;
private HibernateSessionFactory() {}
static {
try {
cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
} catch (HibernateException e) {
// 做日志
throw new RuntimeException("hibernate初始化错误", e);
}
}
public static Session getSession() {
return sessionFactory.getCurrentSession();
// return sessionFactory.openSession();
}
}
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
private static Configuration cfg;
private static SessionFactory sessionFactory;
private HibernateSessionFactory() {}
static {
try {
cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
} catch (HibernateException e) {
// 做日志
throw new RuntimeException("hibernate初始化错误", e);
}
}
public static Session getSession() {
return sessionFactory.getCurrentSession();
// return sessionFactory.openSession();
}
}