package util;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static Logger logger = Logger.getLogger(HibernateUtil.class);
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure("hibernate.cfg.xml")
.buildSessionFactory();
} catch (Throwable ex) {
logger.error(ex, ex);
throw new ExceptionInInitializerError(ex);
}
}
public static ThreadLocal session = null;
public static Session currentSession() throws HibernateException {
if (session == null) {
session = new ThreadLocal();
}
return currentSession(true);
}
public static Session masterSession() throws HibernateException {
// Open a new Session, if this Thread has none yet
try {
return sessionFactory.openSession();
} catch (Throwable ex) {
logger.error(ex, ex);
throw new HibernateException(ex);
}
}
public static Session currentSession(boolean create)
throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
try {
if (s == null && create) {
logger.debug("***to create a session***");
s = sessionFactory.openSession();
s.connection().setAutoCommit(false);
session.set(s);
}
return s;
} catch (Throwable ex) {
logger.error(ex, ex);
throw new HibernateException(ex);
}
}
/**
*
* 什么都不做
*
* @throws HibernateException
*
*/
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
org.hibernate.Transaction trans = s.getTransaction();
if (trans != null && trans.isActive()) {
logger.debug("incompleted transaction");
}
session.set(null);
if (s != null) {
s.close();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
springAop.rar_AOP java_cglib_spring aop
共37个文件
xml:10个
class:9个
java:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 68 浏览量
2022-09-21
04:56:44
上传
评论
收藏 24KB RAR 举报
温馨提示
spring aop 编程,cglib ,切面编程
资源推荐
资源详情
资源评论
收起资源包目录
springAop.rar (37个子文件)
www.pudn.com.txt 218B
springAop
bin
beans.xml 2KB
dao
imp
BeanDaoImp.class 1KB
BeanDao.class 268B
aop
AnnotationAspectJ.class 841B
XmlAspectJ.class 494B
build.xml 25KB
bean
Foo.class 244B
UnitBean.hbm.xml 1KB
UnitBean.class 884B
HelloService.class 600B
unit
Main.class 1KB
build-dist.properties 599B
project.xml 2KB
project.properties 647B
hibernate.cfg.xml 903B
util
HibernateUtil.class 2KB
aop
.settings
org.hibernate.eclipse.console.prefs 112B
.project 385B
.classpath 1KB
java
beans.xml 2KB
dao
BeanDao.java 226B
imp
BeanDaoImp.java 615B
meta-inf
aop
XmlAspectJ.java 117B
AnnotationAspectJ.java 404B
build.xml 25KB
bean
HelloService.java 199B
UnitBean.hbm.xml 1KB
UnitBean.java 717B
Foo.java 42B
unit
Main.java 681B
build-dist.properties 599B
classes
project.xml 2KB
project.properties 647B
hibernate.cfg.xml 903B
util
HibernateUtil.java 2KB
${hbm2ddl.sql.dir}
bestunix.sql 147B
共 37 条
- 1
资源评论
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功