HibernateUtil.java
作者:互联网
package com.lqx.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
//声明一个私有的静态final类型的Configuration对象
private static final Configuration config;
//声明一个私有的静态final类型的SessionFactory对象
private static final SessionFactory factory;
//通过静态代码块构建sessionFactory
static {
config=new Configuration().configure();
factory=config.buildSessionFactory();
}
//提供一个公有的静态方法供外部访问,并返回一个session对象
public static Session getSession() {
return factory.openSession();
}
}
标签:HibernateUtil,java,factory,SessionFactory,hibernate,static,Configuration,final 来源: https://www.cnblogs.com/scxmm/p/14993099.html