【发布时间】:2018-01-20 16:12:30
【问题描述】:
只读模式下不允许写入操作 (FlushMode.MANUAL):将 Session 转换为 FlushMode.COMMIT/AUTO 或从事务定义中删除“readOnly”标记。 在 org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
【问题讨论】:
只读模式下不允许写入操作 (FlushMode.MANUAL):将 Session 转换为 FlushMode.COMMIT/AUTO 或从事务定义中删除“readOnly”标记。 在 org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
【问题讨论】:
在你的弹簧上下文部分,设置以下内容。
<!--default is required transaction-->
<tx:method name="*"/>
我认为您的当前设置为:
<tx:method name="*" read-only="true" propagation="REQUIRED" />
您还可以将@Transactional(readOnly = false) 设置为需要写入数据库的类方法(比如持久化、更新或删除等DAO 类方法)。
@Transactional(readOnly = false)
public void UpdateEmployee() {
...
...
}
【讨论】: