Hibernate getCurrentSession() 方法的细节
来源:互联网 发布:淘宝开的店铺怎么关闭 编辑:程序博客网 时间:2024/06/09 20:54
1、在 hibernate.cfg.xml 中添加配置
<property name="current_session_context_class "> thread </property>//告诉 hibernate,session 由当前线程产生。
2、不需要写 sessio.close(),在事务提交时会自动关闭(由 hibernate内部完成)
@Testpublic class SessionCreateTest extends HiberanteUtils{/** * crud操作必须在transaction的环境下运行 * session和事务绑定在一起了 */@Testpublic void testGetGurrentSession(){Session session = sessionFactory.getCurrentSession();Transaction transaction = session.beginTransaction();Classes classes = (Classes)session.get(Classes.class, 1L);transaction.commit();//session.close();}}
3、CURD都需要事务。
因为是一个线程,所以整个方法中一个session,一个事务;
保证了整个业务操作的安全性。
0 0
- Hibernate getCurrentSession() 方法的细节
- 关于Hibernate的getCurrentSession()!
- hibernate中openSession()方法和getCurrentSession()方法的区别
- Hibernate中使用GetCurrentSession()方法
- Hibernate SessionFactory中openSession和getCurrentSession方法的区别
- Hibernate SessionFactory中openSession和getCurrentSession方法的区别
- Hibernate 中的 openSession和getCurrentSession 方法的区别
- hibernate框架中附带提交事务的方法getCurrentSession()
- hibernate的openSessionFactory和getCurrentSession
- spring和hibernate整合使用getCurrentSession方法
- hibernate获取session的两种方式分别是openSession() 方法和getCurrentSession() 方法。
- hibernate 的openSession和getCurrentSession的区别
- hibernate 的 openSession 和 getCurrentSession 的实现
- Hibernate getCurrentSession 与 openSession() 的区别
- Hibernate openSession() 和 getCurrentSession的区别
- Hibernate openSession() 和 getCurrentSession的区别
- Hibernate中openSession 和 getCurrentSession 的区别
- hibernate的session判断-openSession和getCurrentSession
- 解决输入vi不等于vim的问题
- UVA165连续邮资问题
- 原串翻转
- HDOJ 2036 求多边形面积
- 1001. A+B Format (20)
- Hibernate getCurrentSession() 方法的细节
- 金融系统中PBOC/EMV的TLV的算法实现(含C++/C#)
- 一些索引的限制
- 页面置换算法
- 将110号员工的工资修改为其所在部门的平均工资多100元
- iOS 中获得键盘的弹出和隐藏
- 第4周—项目3.(3)单链表递增
- 安卓控件使用系列18:DatePicker日期控件和TimePicker时间控件的使用
- uva 11354 bond 倍增