sessionFactory.getCurrentSession()的引出
当业务逻辑中需要开启事务执行,业务逻辑也要调用底层操作数据库的函数,那函数也要开启事务操作。
如果用sessionFactory.openSession()的话会引起处理不在同一个事务中,会造成出错。所以必须保证它们的事务都是相同的
sessionFactory.getCurrentSession()
需要在Hibernate.cfg.xml中配置
<!-- 用于配置当前线程用的 -->
<property name="current_session_context_class">thread</property>
所以需要用到当前事务
sessionFactory.getCurrentSession()的引出的更多相关文章
- hibernate 的SessionFactory的getCurrentSession 与 openSession() 的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession不会. 2 getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而ope ...
- 关于SessionFactory的不同实现类分别通过getCurrentSession()方法 和 openSession() 方法获取的Session对象在保存对象时的一些区别
一.单向多对一关联关系 一).使用LocalSessionFactoryBean类,即在applicationContext中配置的 <!-- 配置SessionFactory 使用LocalS ...
- Hibernate中的GetCurrentSession()方法
从3.0.1版本开 始,Hibernate增加了SessionFactory.getCurrentSession()方法. 采用getCurrentSession()创建的session在commit ...
- Hibernate getCurrentSession()和openSession()的区别
通过getCurrentSession()创建的Session会绑定到当前线程上:openSession()不会. 通过getCurrentSession()获取Session,首先是从当前上下文中寻 ...
- Hibernate中openSession() 与 getCurrentSession()的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...
- SessionFactory、HibernateTemplate、HibernateDaoSupport之间的关系说明
在接触HibernateTemplate之前,我们知道,在对数据库进行CRUD操作之前,需要开启session.transaction等等.在hibernate学习过程中,我们知道了,得到sessio ...
- openSession和getCurrentSession的比较
在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法. 在进行配置信息管理时,我们一般进行一下简单步骤: Configuration cfg = n ...
- Spring整合Hibernate 一 - 注入SessionFactory
Spring3 整合 Hibernate4 - 注入SessionFactory 版本: spring-framework-3.2.4.RELEASE hibernate-release-4.2.5. ...
- springboot 获取hibernate 的 SessionFactory
注入bean package cn.xiaojf; import cn.xiaojf.today.data.rdb.repository.RdbCommonRepositoryImpl; import ...
随机推荐
- CentOS下对Apache的中文乱码处理
# vi /etc/sysconfig/i18nLANG="en_US.UTF-8"SYSFONT="latarcyrheb-sun16" 默认的语言是英文,如 ...
- 开启MySQL慢查询日志
1.修改my.cnf或my.ini 1).linux----------------------------------- /etc/my.cnf 文件 [mysqld] long_query_ti ...
- Django学习笔记——安装(linux环境)
1. 下载安装Django pip install Django== 测试是否安装成功 >>> import django>>> django.VERSION (1 ...
- [转载]破解TexturePacker加密资源
最近我们要开一个新项目,UI与交互打算借鉴当前正火的<圣火英雄传>,程序开发为了和美术制作并行,打算用圣火的资源暂代使用.我解压圣火apk,发现用TexturePacker命令行无法把它的 ...
- ubuntu下安装与测试mysql
1.在决定安装mysql之前,要先确定系统是否已经安装mysql. 输入: 1 mysql 结果:说明尚未安装mysql The program 'mysql' is currently notins ...
- GitHub 教程 in Ubuntu
Follow these steps to configure github if you are the first time to use Github 1. Sign up a username ...
- 《OD学hadoop》第二周0703
hdfs可视化界面: http://beifeng-hadoop-01:50070/dfshealth.html#tab-overview yarn可视化界面: http://beifeng-hado ...
- 编译Apache Hadoop2.2.0源代码
Hadoop2的学习资料很少,只有官网的少数文档.如果想更深入的研究hadoop2,除了仅看官网的文档外,还要学习如何看源码,通过不断的调试跟踪源码,学习hadoop的运行机制. 1.安装CentOS ...
- linux常用头文件及说明
linux常用头文件及说明 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言,assert(表达式)<glib.h>:GCC.GTK,GNOM ...
- 如何扩展VCL的hint
默认的Hint窗口展现如下: 这种情况下可以操作有窗口的背景颜色,字体样式 Application.Color 有的时候仅仅是文字满足不了我们的需求,比例如下格式: 这个时候就应该执行以下步骤: 1. ...