import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
//创建会话工厂
static SessionFactory factory;
static {
//1.初始化hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
//2.创建Session工厂
factory = cfg.buildSessionFactory();
}
//获取Session对象
public static Session findSession() {
return factory.getCurrentSession();
}
}