OpenSession()和getCurrentSession的联系和区别
来源:互联网 发布:天天特价淘宝 编辑:程序博客网 时间:2024/05/17 09:34
我们获取链接数据库的Session有两种方法
这里我们讨论一个通过SessionFactory获取 Session的两个方法 openSession() 一个 getCurrentSession();
1. openSession() 是获取一个新的session
2. getCurrentSession () 获取和当前线程绑定的session,换言之,在同一个线程中,我们获取的session是同一session,这样可以利于事务控制
如果希望使用getCurrentSession 需要配置 hibernate.cfg.xml中配置.
3. 如何选择
原则:
①如果需要在同一线程中,保证使用同一个Session则,使用getCurrentSession()
②如果在一个线程中,需要使用不同的Session,则使用opentSession()
4. 通过 getCurrentSession() 获取的session在事务提交后,会自动关闭,通过openSession()获取的session则必须手动关闭
0 0
- OpenSession()和getCurrentSession的联系和区别
- opensession()和getcurrentsession()的联系
- openSession 和getCurrentSession的区别
- getCurrentSession()和openSession()的区别
- getCurrentSession 和 openSession的区别
- openSession 和getCurrentSession的区别
- OpenSession和GetCurrentSession的区别
- openSession 和getCurrentSession的区别
- Hibernate的openSession()和 getCurrentSession()联系
- openSession和getCurrentSession区别
- opensession 和getcurrentsession区别
- openSession和getCurrentSession区别
- opensession和getCurrentSession区别
- openSession和getCurrentSession区别
- hibernate openSession和getCurrentSession区别和联系、get和load的区别
- hibernate 的openSession和getCurrentSession的区别
- Hibernate openSession() 和 getCurrentSession的区别
- hibernat中getCurrentSession 和openSession的区别
- 算法分析---寻找丑数
- 各种数据库查询前几条数据的方法
- ubuntu下解压缩文件
- [leetCode]:Evaluate Reverse Polish Notation
- 特征提取->LBP特征(1)
- OpenSession()和getCurrentSession的联系和区别
- JS实现数字转换为货币汉字大写数字的方法详解
- 也谈如何获得PostgreSQL序列的当前值(最后值)
- 使用PCL::GPU::遇到问题
- 运行locate,找不到mlocate.db
- 通过mysql workbench可视化开发mysql
- Java NIO使用及原理分析(三)
- VB去除窗体(对话框)左上角图标
- FFMPEG视音频编解码零基础学习方法