org.hibernate.HibernateException: get is not valid without active transaction

在配置文件中已经默认开启了本地Session 但还是爆了 org.hibernate.HibernateException: get is not valid without active transaction 的错误
这里写图片描述

错误原因:

这里写图片描述

使用SessionFactory的getCurrentSession获取本地Session,未开启事务就使用Session

解决办法:

不管是查询还是修改都开启事务在进行。

这里写图片描述

猜你喜欢

转载自blog.csdn.net/l1336037686/article/details/80261420