- 在从 5.1 升到 5.2及以上 时遇到这个问题了
- 像是嵌套事务问题
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3552)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1444)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1440)
解决方案如下:
Hibernate now conforms with the JPA specification to
not allow flushing updates outside of a transaction boundary.
To restore 5.1 behavior, allowing flush operations outside of a transaction boundary,
set hibernate.allow_update_outside_transaction=true.
Hibernate现在符合JPA规范,不允许刷新事务边界之外的更新。要恢复5.1行为,
允许事务边界之外的刷新操作,请设置hibernate.allow_update_outside_transaction=true。
from Hibernate ORM 5.2
在hibernate配置文件增加如下语句:
<prop key="hibernate.allow_update_outside_transaction">true</prop>