使用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>