openSession和getCurrentSession的比较
来源:互联网 发布:录音麦克风推荐 知乎 编辑:程序博客网 时间:2024/05/18 03:12
在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法。
在进行配置信息管理时,我们一般进行一下简单步骤:
Configuration cfg = new Configuration();
SessionFactory sf = cfg.configure().buildSessionFactory(); //解析并建立Session工厂
对于上述的两个方法,有以下区别:
注意 :在实际开发中,往往使用getCurrentSession多,因为一般是处理同一个事务(即是使用一个数据库的情况),所以在一般情况下比较少使用openSession或者说openSession是比较老旧的一套接口了;
对于getCurrentSession 来说,有以下一些特点:
1.用途,界定事务边界
2.事务提交会自动close,不需要像openSession一样自己调用close方法关闭session
3.上下文配置(即在hibernate.cfg.xml)中,需要配置:
(需要注意,这里的current_session_context_class属性有几个属性值:jta
a).thread使用connection 单数据库连接管理事务
b).jta (java
下面是openSession 和 getCurrentSession 简单实例的区别 :
1.openSession方式 :
}
2.getCurrentSession方式 :
}
Student 类代码 :
package com.hibernate.model;
public class Student {
}
- openSession和getCurrentSession的比较
- openSession和getCurrentSession的比较
- openSession和getCurrentSession的比较
- openSession和getCurrentSession的比较
- openSession和getCurrentSession的比较
- openSession和getCurrentSession的比较
- openSession和getCurrentSession 比较
- 比较openSession和getCurrentSession
- java openSession和getCurrentSession的比较
- openSession 和getCurrentSession的区别
- opensession()和getcurrentsession()的联系
- getCurrentSession()和openSession()的区别
- getCurrentSession 和 openSession的区别
- openSession 和getCurrentSession的区别
- OpenSession和GetCurrentSession的区别
- openSession 和getCurrentSession的区别
- 9.Hibernate OpenSession&getCurrentSession的比较
- OpenSession()和getCurrentSession的联系和区别
- java中queue的使用
- datalines与datalines4语句详解
- hdu 5546(DFS或BFS)
- rabbitmq分布式集群架构
- 单点登录服务的实现和机制
- openSession和getCurrentSession的比较
- AIO简介
- EventHub
- git 中的非破坏性操作
- MySQL存储过程详解
- BigDecimal用法详解
- HDU 6214
- 数据结构学习笔记(四)--关于线性表的一个小疑问
- android arrayAdapter使用