Hibernate之openSession和getCurrentSession
来源:互联网 发布:网络网站工程师培训 编辑:程序博客网 时间:2024/05/11 04:19
hibernate通过SessionFactory有两种方式获取session: 一种是openSession 一种是getCurrentSession
区别:
a)openSession创建session时autoClassSessionEnabled参数为false,即在事务结束后不会自动关闭session 需要手动关闭
b)getCurrentSession创建session时autoCloseSessionEnabled,flushBeforeCompletionEnabled都为true 事务结束后自动关闭session
如果使用getCurrentSession获取session时 需要在hibernate.cfg.xml中加入如下配置
本地事务
<property name="hibernate.current_session_context_class">thread</property>
全局事务
<property name="hibernate.current_session_context_class">jta</property>
不然的话会报如下错误:
org.hibernate.HibernateException: No CurrentSessionContext configured!at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:620)at com.itmyhome.model.StudentTest.test(StudentTest.java:26)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597) .........
- Hibernate之openSession和getCurrentSession
- hibernate之opensession和getCurrentSession
- Hibernate之openSession和getCurrentSession
- hibernate openSession和getCurrentSession
- hibernate opensession()和getCurrentSession()
- hibernate之openSession()和getCurrentSession()的区别
- hibernate之openSession 和 getCurrentSession 概述
- Hibernate中的getCurrentSession和openSession
- Hibernate中openSession 和 getCurrentSession
- Hibernate中openSession 和 getCurrentSession
- hibernate openSession和getCurrentSession区别
- HIbernate中openSession和getCurrentSession
- spring+Hibernate openSession()和getCurrentSession()
- Hibernate4之getCurrentSession和openSession
- Hibernate4之getCurrentSession和openSession
- Hibernate4之getCurrentSession和openSession
- Hibernate 之getCurrentSession 与 openSession() 的区别
- Hibernate 之getCurrentSession 与 openSession() 的区别
- 浙江省省赛K题
- [2010Beijing Wc]外星联络
- 我们都需要改变
- poj 2274 线段树+堆
- 人才竞争与垄断
- Hibernate之openSession和getCurrentSession
- 分享一些大牛的Android博客
- 免费天气预报代码 滚动天气预报代码 大全
- ubuntu 11.10 上安装Sun Grid Engine
- 构建高性能的web站点学习笔记三------动态内容缓存
- 浙江省省赛J题
- c# 调用ictclas.dll出现的异常
- ITIL先锋论坛专家风采——杜肖辉
- 【Visual C++】游戏开发笔记十六 讲解一个完整的回合制游戏demo