当业务逻辑中需要开启事务执行,业务逻辑也要调用底层操作数据库的函数,那函数也要开启事务操作。

如果用sessionFactory.openSession()的话会引起处理不在同一个事务中,会造成出错。所以必须保证它们的事务都是相同的

sessionFactory.getCurrentSession()

需要在Hibernate.cfg.xml中配置

<!-- 用于配置当前线程用的 -->
<property name="current_session_context_class">thread</property>

所以需要用到当前事务

sessionFactory.getCurrentSession()的引出的更多相关文章

  1. hibernate 的SessionFactory的getCurrentSession 与 openSession() 的区别

    1 getCurrentSession创建的session会和绑定到当前线程,而openSession不会. 2 getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而ope ...

  2. 关于SessionFactory的不同实现类分别通过getCurrentSession()方法 和 openSession() 方法获取的Session对象在保存对象时的一些区别

    一.单向多对一关联关系 一).使用LocalSessionFactoryBean类,即在applicationContext中配置的 <!-- 配置SessionFactory 使用LocalS ...

  3. Hibernate中的GetCurrentSession()方法

    从3.0.1版本开 始,Hibernate增加了SessionFactory.getCurrentSession()方法. 采用getCurrentSession()创建的session在commit ...

  4. Hibernate getCurrentSession()和openSession()的区别

    通过getCurrentSession()创建的Session会绑定到当前线程上:openSession()不会. 通过getCurrentSession()获取Session,首先是从当前上下文中寻 ...

  5. Hibernate中openSession() 与 getCurrentSession()的区别

    1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...

  6. SessionFactory、HibernateTemplate、HibernateDaoSupport之间的关系说明

    在接触HibernateTemplate之前,我们知道,在对数据库进行CRUD操作之前,需要开启session.transaction等等.在hibernate学习过程中,我们知道了,得到sessio ...

  7. openSession和getCurrentSession的比较

    在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法. 在进行配置信息管理时,我们一般进行一下简单步骤: Configuration cfg = n ...

  8. Spring整合Hibernate 一 - 注入SessionFactory

    Spring3 整合 Hibernate4 - 注入SessionFactory 版本: spring-framework-3.2.4.RELEASE hibernate-release-4.2.5. ...

  9. springboot 获取hibernate 的 SessionFactory

    注入bean package cn.xiaojf; import cn.xiaojf.today.data.rdb.repository.RdbCommonRepositoryImpl; import ...

随机推荐

  1. JavaPersistenceWithHibernate第二版笔记Getting started with ORM-001用JPA和Hibernate实现HellowWorld(JTA、Bitronix)

    一.结构 二.model层 1. package org.jpwh.model.helloworld; import javax.persistence.Entity; import javax.pe ...

  2. 跨平台 c 开发库 tbox v1.6.0,支持跨平台协程

    http://www.oschina.net/news/78582/tbox-v-1-6-0

  3. Hibernate笔记——hql总结

    原文:http://www.cnblogs.com/xiaoluo501395377/p/3376256.html ------------------------------------------ ...

  4. [iOS]如何删除工程里面用cocoapods导入的第三方库

    如何在工程中卸载用cocoapods导入的第三方呢? 1. 打开工程所在文件夹 2. 打开Podfile文件 3. 删除不要的第三方导入命令 4. 然后在回到终端,然后进入到工程目录下,然后更新第三方 ...

  5. zf2 安装

    下载实例程序 ZendSkeletonApplication 解压至D:\xampp\htdocs并重命名为ZendSkeletonApplication 下载Zend Framework 2.0最新 ...

  6. javascript 递归调用

    上源码:underscore.js var flatten = function(input, shallow, output) { if (shallow && _.every(in ...

  7. VIM下CS命令

    01) :vs 文件目录//打开新的目录02) :cs f s 函数名 //查找那些文件中都用这个函数/变量03) :vert diffsplit A函数  //当前函数与A函数做对比(在对比情况下  ...

  8. 堆的 两种实现 (数组和STL)

    基本思想: 两种操作都跟树的深度成正比,所以复杂度  O(log(n)) ; push():在向堆中插入数值时,首先在堆的末尾插入该数值,然后不断向上提直到没有大小颠倒为止. pop(): 从堆中取出 ...

  9. android:descendantFocusability的作用:viewgroup与其上面view的焦点控制,如何让子view失去焦点等。

    ViewGroup的下面这个属性可以控制. 原文: android:descendantFocusability Defines the relationship between the ViewGr ...

  10. vs中常用的快捷键

    VS中常用的快捷键: ctrl+s         保存 ctrl+Shift+S   保存所有VS中打开的所有文件 ctrl+O         打开新文件 ctrl+Shift+O   打开项目 ...