其他分享
首页 > 其他分享> > 2021-06-14

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