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