openSession和getCurrentSession区别
来源:互联网 发布:excel重复数据合计 编辑:程序博客网 时间:2024/06/07 07:14
在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法。
在进行配置信息管理时,我们一般进行一下简单步骤:
Configuration cfg = new Configuration(); // 获得配置信息对象
SessionFactory sf = cfg.configure().buildSessionFactory(); //解析并建立Session工厂
1. Session session = sf.getCurrentSession(); // 获得Session
2. Session session = sf.openSession(); // 打开Session
对于上述的两个方法,有以下区别:
1. openSession 从字面上可以看得出来,是打开一个新的session对象,而且每次使用都是打开一个新的session,假如连续使用多次,则获得的session不是同一个对象,并且使用完需要调用close方法关闭session。
2. getCurrentSession ,从字面上可以看得出来,是获取当前上下文一个session对象,当第一次使用此方法时,会自动产生一个session对象,并且连续使用多次时,得到的session都是同一个对象,这就是与openSession的区别之一,简单而言,getCurrentSession 就是:如果有已经使用的,用旧的,如果没有,建新的。
注意:在实际开发中,往往使用getCurrentSession多,因为一般是处理同一个事务(即是使用一个数据库的情况),所以在一般情况下比较少使用openSession或者说openSession是比较老旧的一套接口了;
截取转载自:http://blog.csdn.net/liyunyun6/article/details/8946501
- openSession和getCurrentSession区别
- opensession 和getcurrentsession区别
- openSession和getCurrentSession区别
- opensession和getCurrentSession区别
- openSession和getCurrentSession区别
- openSession 和getCurrentSession的区别
- hibernate openSession和getCurrentSession区别
- getCurrentSession()和openSession()的区别
- getCurrentSession 和 openSession的区别
- openSession 和getCurrentSession的区别
- openSession和getCurrentSession区别详解
- OpenSession和GetCurrentSession的区别
- openSession 和getCurrentSession的区别
- OpenSession()和getCurrentSession的联系和区别
- Hibernate openSession() 和 getCurrentSession的区别
- hibernat中getCurrentSession 和openSession的区别
- Hibernate openSession() 和 getCurrentSession的区别
- Hibernate中openSession 和 getCurrentSession 的区别
- day21桶排序一个无序数组+求一个无序数组中的中位数
- HDU 4912 LCA+策略
- Java中Synchronized的用法
- 浅谈最短路中的Dijskra算法
- 链表创建队列
- openSession和getCurrentSession区别
- KMP 算法(1):如何理解 KMP
- Spark RDD API
- 批量提取一个文件夹中的文件名
- BZOJ 4806 炮(DP)
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'async-supported'. 错误
- Excel在统计分析中的应用—第三章—数据库统计函数与数据透视表-Part1-(数据查询与筛选、分类汇总)
- 欢迎使用CSDN-markdown编辑器
- UVALive 6575 Odd and Even Zeroes