Hibernate buildsessionfactory method: build sessionfactory
•
Java
buildSessionFactory()
Example
Configuration config = new Configuration().configure(); //创建Configuration对象 SessionFactory sessionFactory = config.buildSessionFactory();
Typical application
private static SessionFactory factory = null; //SessionFactory对象
static{ //静态块
try{
Configuration cfg = new Configuration().configure(); //加载Hibernate配置文件
cfg.addClass(Users.class); //加载实体类
System.out.println("成功的加载了实体类Users");
factory = cfg.buildSessionFactory(); //示例化SessionFactory
System.out.println("成功的创建了SessionFactory示例");
}catch(HibernateException e){
e.printStackTrace();
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
