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

相关文章
已解决 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'.异常错误,已解决
526 0
已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.
|
11月前
报错modify sync object Modify sync object Failed!
报错modify sync object Modify sync object Failed!
38 1
|
Java 关系型数据库 MySQL
定时任务Quzrtz:Failed to override connection auto commit/transaction isolation
定时任务Quzrtz:Failed to override connection auto commit/transaction isolation
125 0
|
SQL 关系型数据库 MySQL
Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
424 0
|
SQL 关系型数据库 MySQL
Deadlock found when trying to get lock; try restarting transaction
Deadlock found when trying to get lock; try restarting transaction
321 1
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
416 0
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
|
Java Spring
Could not obtain transaction-synchronized Session for current thread
报错信息: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread at org.
3033 0