hibernate的session的util的获取与关闭
来源:互联网 发布:检测域名是否被墙 编辑:程序博客网 时间:2024/05/28 03:02
package com.hotel.HButil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HButil {
private static SessionFactory factory;
static {
try {
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
//建立SessionFactory
factory = cfg.buildSessionFactory();
}catch(Exception e) {
e.printStackTrace();
}
}
/*
*打开Session
*/
public static Session getSession() {
return factory.openSession();
}
/*
*关闭Session
*/
public static void closeSession(Session session) {
if (session != null) {
if (session.isOpen()) {
session.clear();
session.close();
}
}
}
public static SessionFactory getSessionFactory() {
return factory;
}
private static SessionFactory factory;
static {
try {
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
//建立SessionFactory
factory = cfg.buildSessionFactory();
}catch(Exception e) {
e.printStackTrace();
}
}
/*
*打开Session
*/
public static Session getSession() {
return factory.openSession();
}
/*
*关闭Session
*/
public static void closeSession(Session session) {
if (session != null) {
if (session.isOpen()) {
session.clear();
session.close();
}
}
}
public static SessionFactory getSessionFactory() {
return factory;
}
}
0 0
- hibernate的session的util的获取与关闭
- Hibernate获取Session的超实用Util工具类
- 获取hibernate的Session
- 解决Hibernate的Session的关闭与开启问题
- hibernate的延迟加载及其与session关闭的矛盾
- 解决Hibernate的Session的关闭与开启问题
- 使用Hibernate框架时创建获取Session和关闭Session的工具类
- hibernate session的获取方式
- hibernate 获取Session 的方式
- spring 控制hibernate的session何时关闭.
- spring 控制hibernate的session何时关闭.
- hibernate关于session的关闭问题
- Hibernate延迟加载Session关闭的解决方案
- Hibernate的Session不会自动关闭
- hibernate关于session的关闭问题
- hibernate关于session的关闭问题
- Hibernate中session的关闭问题
- hibernate关于session的关闭问题
- 阶段总结
- python 愚人排序
- 分布式Session原理,最简单而高效的实现方式
- AT25C02程序编写及疑问解析
- 准备在CSDN知识库建立一个Ext JS的知识库
- hibernate的session的util的获取与关闭
- Mybatis实现原理深入解析 (转载)
- PHP+jq实现验证码
- mysql(for update)悲观锁总结与实践
- SQL 常用字符串处理函数
- freemarker 替换字符串,模板,可以用来动态生成代码
- 常用工具代码总结
- attention model资料收集
- linux-as5u2环境下安装MySQL-5.7.14