天天看點

Hibernate 5 - no transaction is in progress

使用HibernateTemplate進行sql查詢時,程式未見異常,傳回報404錯誤,

将spring日志改成debug級别後,抛錯如下:

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)  
           

解決方案如下:

I believe it is this

"""

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

.

"""

from Hibernate ORM 5.2

在hibernate配置檔案增加如下語句:

                <prop key="hibernate.allow_update_outside_transaction">true</prop>

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

繼續閱讀