您的位置: 首页 > 文章 > Could not obtain transaction-synchronized Session for current thread原因及解决方案 Could not obtain transaction-synchronized Session for current thread原因及解决方案 分类: 文章 • 2024-06-22 12:05:22 问题 用sessionFactory.getCurrentSession()这样获取session,抛了这异常。 解决 必须要将使用了sessionFactory.getCurrentSession()获取session的代码所在的方法加入到事务管理器中;否则获取不到session了。 sessionFactory.getCurrentSession()是要基于事务的,才能实现session生命周期的管理。所以查询方法上用只读事务就ok了。 参考: