Could not obtain transaction-synchronized Session for current thread原因及解决方案

简介: Could not obtain transaction-synchronized Session for current thread原因及解决方案

问题


用sessionFactory.getCurrentSession()这样获取session,抛了这异常。

372338ad8d447071dffb37e61189ff79.png

解决


必须要将使用了sessionFactory.getCurrentSession()获取session的代码所在的方法加入到事务管理器中;否则获取不到session了。


sessionFactory.getCurrentSession()是要基于事务的,才能实现session生命周期的管理。所以查询方法上用只读事务就ok了。


234f396263ba2caffc766753325a78c6.png

相关文章
|
8月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
168 1
|
Web App开发 前端开发
【前端异常】Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
【前端异常】Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
904 0
已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.
Jetson Xavier NX 报错 RuntimeError: There is no current event loop in thread 'Thread-1'.异常错误,已解决
647 0
已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.
|
Java 关系型数据库 MySQL
定时任务Quzrtz:Failed to override connection auto commit/transaction isolation
定时任务Quzrtz:Failed to override connection auto commit/transaction isolation
161 0
|
SQL 关系型数据库 MySQL
Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
469 0
|
Java Spring
【小家java】Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only(下)
【小家java】Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only(下)
【小家java】Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only(下)
Timeout waiting to lock artifact cache ....
Timeout waiting to lock artifact cache ....
Timeout waiting to lock artifact cache ....
|
Java 对象存储 Spring
【小家java】Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only(上)
【小家java】Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only(上)
|
Oracle 关系型数据库 数据库
PMON failed to acquire latch, see PMON dump
前几天,一台Oracle数据库(Oracle Database 10g Release 10.2.0.4.0 - 64bit Production)监控出现"PMON failed to acquire latch, see PMON dump"错误,连接数据库出现短暂异常,告警日志中具体错误如下所...
1149 0