Hibernate 5 - no transaction is in progress


  • 在从 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>

参考:https://developer.jboss.org/thread/278691?_sscc=t


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM