hibernate的session对象
来源:互联网 发布:伤逝 叶倩文 知乎 编辑:程序博客网 时间:2024/04/30 07:04
hibernate中
session对象与connection对象是多对一得关系
即
一个session对应一个connection;
一个connection对应N个session对象。
如何获得session
从sessionFactory中,通过openSession();getCurrentSession();获得 。
两者的区别:
getCurrentSession()返回的Session 自动关闭事务
openSession()返回的Session需要手动关闭事务
openSession()每次拿出一个新的Session;getCurrentSession()返回现有Session(单例模式).
其中getCurrentSession();需要在hibernate。cfg.xml文件中中进行配置
本地事务<propertyname="hibernate.current_session_context_class">thread</property>
全局事务
`<propertyname="hibernate.current_session_context_class">jta</property>`
全局事务:资源管理器管理和协调的事务,可以跨越多个数据库和进程。
本地事务:在单个 EIS 或数据库的本地并且限制在单个进程内的事务。本地事务不涉及多个数据来源。
在hibernate中,session对象有以下方法:
save();
update();
delete();
createquery();
dowork();
在hibernate4中官方推荐使用Session doWork()方法进行jdbc操作
Hibernate3.3.2版本中getSession().connection()已被弃用
public interface Work {//Execute the discrete work encapsulated by this work instance using the supplied connection.//@param connection The connection on which to perform the work.// @throws SQLException Thrown during execution of the underlying JDBC interaction.// @throws HibernateException Generally indicates a wrapped SQLException.public void execute(Connection connection) throws SQLException{} //在execute()中进行JDBC操作
0 0
- hibernate的session对象
- Hibernate的学习总结(Session对象)
- Hibernate session加载对象的过程
- Hibernate 4 获取session对象的变化
- Hibernate中的Session对象的一级缓存
- JSP中的session与Hibernate的session对象同步问题。
- HIbernate 创建Session 对象
- hibernate中的Session对象
- Hibernate 框架Session对象
- Hibernate中的Session对象
- Hibernate Session篇--Hibernate的缓存及对象的状态
- Hibernate Session篇--Hibernate的缓存及对象的状态
- Hibernate学习(三):Session的缓存及对象的状态
- Hibernate中Session的缓存及对象的状态
- Hibernate学习(三):Session的缓存及对象的状态
- Hibernate对象的状态,session的clear()和evict()
- Hibernate对象的三种状态&&Session的常用方法
- Hibernate的Query和Session对象的示例
- Binary XML file line #98:Error inflating class Button
- MVC 基架不支持 Entity Framework 6 或更高版本(转)
- [MT6574 lk] USB,RDX,ODIN
- 基础知识之关于far,near,huge,base指针
- LeetCode----Lowest Common Ancestor of a Binary Tree
- hibernate的session对象
- 使用commons-io-2.0 API来实现监听文件变化
- 使用JavaScript获取textare输入值的问题
- CodeForces - 630H Benches (组合数学)
- HOJ 1603 Brackets Sequence
- Java中IO流操作大全
- 大型网站架构系列:电商网站架构案例(1)
- 迪米特法则---先看了两遍书,在看后面的内容时发现还是没理解全,第三遍终于清晰了
- 1000:A+B Problem