hibenate openSession和getCurrentSession
来源:互联网 发布:windows 直接登录 编辑:程序博客网 时间:2024/06/09 18:20
openSession和getCurrentSession的根本区别在于有没有绑定当前线程,所以,使用方法有差异:
openSession:没有绑定当前线程,所以,使用完后必须关闭,
当调用SessionFactory的openSession方法时,它总是创建一个完全全新的session给你。你需要显示的刷新并且关闭session对象。
因为session对象不是线程安全的,在多线程环境中你需要为每一个请求创建一个session对象(例如web应用的每一个请求)。
当调用SessionFactory的getCurrentSession方法时,它会返回Hibernate上下文中的Session,并且有hibernate管理。它绑定到事物范围。
当调用SessionFactory的getCurrentSession方法时,如果不存在他会创建一个新的Session对象,如果在当前的hibernate上下文中存在,则返回同样的Session对象。
它会自动地flush和close,当事物结束的时候,所以无需多余处理。如果你在单线程环境下使用hibernate,你应该用getCurrentSession,它的性能比较好。
如果你要使用getCurrentSession,你需要配置如下:
<!--使用getCurrentSession--><property name="hibernate.current_session_context_class">thread</property>
阅读全文
0 0
- hibenate openSession和getCurrentSession
- openSession和getCurrentSession区别
- hibernate openSession和getCurrentSession
- openSession和getCurrentSession
- openSession和getCurrentSession 比较
- opensession 和getcurrentsession区别
- getCurrentSession和openSession
- hibernate opensession()和getCurrentSession()
- openSession和getCurrentSession
- openSession和getCurrentSession
- openSession和getCurrentSession区别
- openSession和getCurrentSession
- openSession和getCurrentSession
- opensession和getCurrentSession区别
- openSession和getCurrentSession
- 比较openSession和getCurrentSession
- openSession和getCurrentSession
- openSession和getCurrentSession区别
- opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像
- C++中回调(CallBack)的使用方法
- 设计模式:单例
- sas hash2 多对多的情况
- 小白必看Python视频基础教程
- hibenate openSession和getCurrentSession
- 在 Windows 7上安装 TensorFlow
- C#回顾学习笔记二十六:String与StringBuilder的区别
- 红黑树剖析
- 第1章 搭建Android源码工作环境
- finally、final和finalize方法的区别
- BubbleSort
- DPDK+OVS+QEMU搭建vhost-user实验环境
- Hibernate配置以及增删改查实现