Could not obtain transaction-synchronized Session for current thread原因及解决方案
一、问题的产生

二、问题的解决过程
(1)先看下Hibernate相关的配置

(2)从网上找答案

- (1)必须要将使用了sessionFactory.getCurrentSession()获取session的代码所在的方法加入到事务管理器中;否则获取不到session了。
- (2)sessionFactory.getCurrentSession()是要基于事务的,才能实现session生命周期的管理。所以我们查询方法上用个只读事务就ok了。
(3)解决问题


三、小结
Could not obtain transaction-synchronized Session for current thread原因及解决方案的更多相关文章
- 记一次bug思考过程:HibernateException: Could not obtain transaction-synchronized Session for current thread
场景:把从客户端提交的任务放到线程池执行 异常:HibernateException: Could not obtain transaction-synchronized Session for cu ...
- Hibernate4中使用getCurrentSession报Could not obtain transaction-synchronized Session for current thread
架个spring4+hibernate4的demo,dao层直接注入的sessionFactory,然后用getCurrentSession方法获取session,然后问题来了,直接报错: Could ...
- 关于Hibernate Could not obtain transaction-synchronized Session for current thread
转载自 http://blog.csdn.net/flyjiangs/article/details/51537381 最近几年一直再搞android,最近闲下来了,顺便玩一下web. 整了个最新版本 ...
- 关于Could not obtain transaction-synchronized Session for current thread 这个异常。
Could not obtain transaction-synchronized Session for current thread 这个异常之前非常让我头大.对于网上的各种说法都试了一下反正都不 ...
- org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
spring与hibernate整合报错 org.hibernate.HibernateException: Could not obtain transaction-synchronized Ses ...
- Hibernate Could not obtain transaction-synchronized Session for current thread问题处理
项目通过Hibernate查询时报出如下错误: Hibernate Could not obtain transaction-synchronized Session for current thre ...
- Hibernate4 No Session found for current thread原因
Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for curre ...
- SSH2 No Session found for current thread原因
Hibernate4 与 spring3 集成之后, 如果在取得session 的地方使用了getCurrentSession, 可能会报一个错:“No Session found for curre ...
- Could not obtain transaction-synchronized Session for current thread 错误的解决方法!
BsTable bsTable = new BsTable(); // String time = request.getParameter("date"); String tim ...
随机推荐
- 单元测试(一)-NUnit基础
单元测试作为提高代码和软件质量的有效途径,其重要性和益处自不必多说,虽然我没有实践过TDD之类,但坚信单元测试的积极作用.作为一种开发方法,单元测试早在上世纪70年代就已经在Smalltalk语言被运 ...
- OpenCV 图像特效
1.RGB ->灰度 #灰度 方式1 img=cv2.imread('b.png',0) img1=cv2.imread('b.png',1) height=img1.shape[0] widt ...
- Expo大作战(十)--expo中的App Icon,expo中的Assets,expo中的ErrorHandling错误处理
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- 【Python】TypeError: a bytes-like object is required, not 'str'解决
对所使用的字符串类型调用encode()方法进行转换即可
- Android Studio之could not reserve enough space for object heap报错
在用AndroidStudio时出现这样的错误: 搞了半天终于找到了解决办法,但是很麻烦.就是每次创建工程后,在gradle.properties文件中加入如下代码: org.gradle.jvma ...
- Java修改服务器(tomcat)响应头 Server:Apache-Coyote/1.1
Server:Apache-Coyote/1.1 :很多人有说有漏洞,是否有没研究过, 只知道Apache-Coyote是tomcat处理socket链接信息,包装request.response等底 ...
- Asp连接Oracle (包含绿色版12.2客户端和ODBC驱动安装)
我能操作的终端电脑是一台linux系统可以上互联网 ,服务器在部署在独立的私网上,不方便上互联网.服务器是2008R2.安装vs不是很方便.其所linux下作开发不是不可以,java php mono ...
- mariadb使用\s查看用户权限
今天出现一个问题就是:给zabbix用户赋予权限 语句如下: grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix' 按照这样的说法应 ...
- 极限编程核心价值:沟通(Communication)
原文:https://deviq.com/communication 极限编程核心价值:简单(Simplicity) 极限编程核心价值:沟通(Communication) 极限编程核心价值:反馈(Fe ...
- 1.js基础(以通俗易懂的语言解释JavaScript)
1.JavaScript组成: ECMAScript: 解释器.翻译 -->几乎没有兼容问题 DOM: Document Object Model -->有一些操作不兼容 BOM: Bro ...