Hibernate工具类之获取SessionFactory
来源:互联网 发布:反恐精英刀具可以优化 编辑:程序博客网 时间:2024/06/05 18:54
Hibernate工具类之获取SessionFactory和Session
由于SessionFactory是重量级的,也就是说创建SessionFactory需要消耗大量的资源,所以在整个应用程序中最好只存在一个SessionFactory,这就需要把获取SessionFactory的方法单独抽取出来封装成一个工具类
package com.hibernate.utils;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;public class HbnUtils { private static SessionFactory sessionFactory; /** * * @return Session */ public static Session getSession(){ return getSessionFactory().getCurrentSession(); } /** * SessionFactory是重量级的 * 最好做成单例模式 * @return SessionFactory */ public static SessionFactory getSessionFactory(){ //保证SessionFactory为单例 if (sessionFactory == null ||sessionFactory.isClosed()) { sessionFactory = new Configuration().configure().buildSessionFactory(); } return sessionFactory; }}
有问题加511906138学习群讨论
1 0
- Hibernate工具类之获取SessionFactory
- hibernate获取sessionFactory工具类
- hibernate 获取 SessionFactory 的工具类
- Hibernate创建sessionFactory工具类
- 获取SessionFactory的工具类
- Hibernate之SessionFactory
- hibernate之SessionFactory
- hibernate SessionFactory的获取方法
- hibernate 获取SessionFactory的方法
- Hibernate创建sessionFactory,session和关闭session的工具类
- hibernate参考手册之---SessionFactory配置
- Hibernate之Configuration,SessionFactory,Session
- Hibernate之Configuration,SessionFactory,Session
- Hibernate进阶之SessionFactory二级缓存
- Hibernate之SessionFactory和Session
- Hibernate之Configuration,SessionFactory,Session
- Hibernate之Configuration,SessionFactory,Session
- Hibernate之Configuration,SessionFactory,Session
- WebStorm中运行React15.3.1控制台报“React.render is not a function”错误
- 概率p输出1,概率1-p输出0,等概率输出0和1
- PDO数据访问抽象层
- 使用IDEA和gradle搭建Spring MVC和MyBatis开发环境
- libevent源码深度剖析七
- Hibernate工具类之获取SessionFactory
- Django Python 获取请求头信息Content-Range
- Leetcode 212. Word Search II
- iOS 自动布局框架 Masonry
- Trafodion 如何实现分页
- No subscribers registered for event class
- 算法设计与分析(3)-- Median of Two Sorted Arrays(难度:hard)
- 一个菜鸟的IT路
- tableView 分割线宽度没占据整个屏幕的宽度