Rhyme/Hibernate getCurrentSession()与openSession()的区别
来源:互联网 发布:微博十大网络主播投票 编辑:程序博客网 时间:2024/06/06 00:20
Hibernate getCurrentSession()与openSession()的区别
sessionFactory.getCurrentSession()会查看当前上下文环境中有没有session,没有则创建,,在这个session没有提交之前,获得的session永远是同一个session,session一旦提交,则会获取新的session,另外使用getCurrentSession()获得的session不用手动执行session.close()方法
另外使用getCurrentSession()方法需要指定应用的上下文,具体配置如下图
而sessionFactory.openSession()每次调用都会创建一个新的session,所以不建议使用
为什么这么做?
原因是,openSession()可能导致事务方法出现不一致的情况
当我在执行事务控制的时候,分别调用两个DAO中的方法,且这两个方法是同步的,这个时候,如果两个DAO中分别使用的都是openSession()方法,那么就不能做到addUser()这个方法的事物一致性。
阅读全文
0 0
- Rhyme/Hibernate getCurrentSession()与openSession()的区别
- Hibernate getCurrentSession 与 openSession() 的区别
- Hibernate 之getCurrentSession 与 openSession() 的区别
- hibernate openSession()与getCurrentSession()的区别
- Hibernate 之getCurrentSession 与 openSession() 的区别
- Hibernate getCurrentSession 与 openSession() 的区别
- hibernate之openSession()与getCurrentSession()的区别
- Hibernate 中getCurrentSession 与 openSession() 的区别
- Hibernate getCurrentSession 与 openSession() 的区别
- 【Hibernate】 - openSession与getCurrentSession区别
- getCurrentSession 与 openSession() 的区别 getCurrentSession 与 openSession() 的区别
- getCurrentSession 与 openSession() 的区别
- getCurrentSession 与 openSession() 的区别
- getCurrentSession()与openSession()的区别
- getCurrentSession 与 openSession() 的区别
- getCurrentSession 与 openSession() 的区别
- getCurrentSession 与 openSession() 的区别
- openSession与getCurrentSession的区别
- cs231n笔记(8)--卷积神经网络CNN
- java包装类默认值==比较空指针异常详解
- 深入浅出mysql-sql基础
- 数据结构实验之排序四:寻找大富翁
- 防止SQL注入:永远不要信任外界输入的数据,特别是来自于客户端的,包括选择框、表单隐藏域和 cookie
- Rhyme/Hibernate getCurrentSession()与openSession()的区别
- 《PCL点云库学习&VS2010(X64)》Part 48 基于霍夫变换的点云平面检测法
- spring boot guava cache 缓存学习
- 微信小程序商品筛选,侧方弹出动画选择页面
- js实现星星评分功能的实现,并获取评分多少的功能(附源码)
- 学习矢量量化-LVQ
- Scala中for循环逆序遍历数组
- Hcdp认证培训是什么?
- 生成对抗网络(GAN)的理论与应用完整入门介绍