Hibernate getCurrentSession()和openSession()的区别
来源:互联网 发布:网络巨头公司 编辑:程序博客网 时间:2024/04/30 05:51
Hibernate随记——getCurrentSession()和openSession()的区别
getCurrentSession()方法:(获取当前Session)在获取Session时,会先从上下文中找Session对象,如果找到了就返回这个Session;如果没有找到,则会返回一个新的Session。(session的事务提交之后或者session.close()之后,上下文中就没有Session对象了,必须重新创建)。此方法获取的Session在事务提交之后自动关闭,不可以手动关闭。手动关闭会报错!!!
如果要获取当前线程的Session,则需要配置hibernate.cfg.xml文件:
thread 指的是在当前线程内获取currentSession。<property name="current_session_context_class">thread</property>
- openSession()方法:(获取新Session)每次调用时会得到一个新的Session,该方法获得的Session需要手动关闭。
0 0
- hibernate 的openSession和getCurrentSession的区别
- Hibernate openSession() 和 getCurrentSession的区别
- Hibernate openSession() 和 getCurrentSession的区别
- Hibernate中openSession 和 getCurrentSession 的区别
- Hibernate 中 openSession()和getCurrentSession() 的区别
- Hibernate openSession()和getCurrentSession()的区别
- Hibernate openSession() 和 getCurrentSession的区别
- hibernate之openSession()和getCurrentSession()的区别
- Hibernate openSession() 和 getCurrentSession的区别
- 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的区别
- Jetty 的工作原理以及与 Tomcat 的比较
- iOS开发-特殊数据类型-Id
- 这是我本科和读研期间的所做的一些项目,有个别是觉得不错的,收集来的。
- 欢迎使用CSDN-markdown编辑器
- Linux下部署启动Tomcat
- Hibernate getCurrentSession()和openSession()的区别
- (13.1.3.2)PMBOK之三:十大知识领域之范围管理
- (转)解决IntelliJ IDEA cannot resolve symbol R 错误
- Kubernetes 1.6新增主要功能介绍
- [openstack]NFVI特性之实时虚拟机(一)
- OD调试多线程(转)
- 简介JS脚本病毒解密及相关分析方法
- VB程序逆向反汇编常见的函数(转)
- 发现一个开发小帮手:Zeal Mac版叫做:Dash 集成多数开发语言API