2021-06-14
作者:互联网
升级SessionFactory
package com.q.utils;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtils {
private static SessionFactory sf;
static {
try {
Configuration con = new Configuration().configure();
sf = con.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
return sf;
}
public void closeSessionFactory() {
sf.close();
}
}
SessionFactory sessionFactory = HibernateUtils.getSessionFactory();
Session session = sessionFactory.openSession();
配置
<hibernate-mapping>
<property name="hibernate.current_session_context_class">thread</property>
</hibernate-mapping>
查询
结果
标签:06,14,public,SessionFactory,getSessionFactory,static,2021,Configuration,sf 来源: https://blog.csdn.net/qq_45843901/article/details/117903435