org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
在使用hibernate 的 HibernateTemplate的保存方法时出现该异常,
本人经过研究与查资料找到的两种解决办法如下:
1、在调用保存方法前将flushMode改为auto
this.ht.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
2、修改web.xml中spring的过滤器:OpenSessionInViewFilter参数如下
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
分享到:
相关推荐
其中一种较为常见的异常是 `org.springframework.dao.InvalidDataAccessApiUsageException`。这类异常通常发生在使用Spring框架进行数据库操作(如增、删、改)时,特别是在采用Spring的注解式事务管理机制时。 ###...
`org.springframework.orm.ObjectRetrievalFailureException`、`org.springframework.beans.factory.BeanCreationException` 和 `org.springframework.dao.InvalidDataAccessApiUsageException` 等。 #### 二、`org...
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker ...
<bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <bean id="urlMapping" class="org.springframework.web.servlet.handler....
`HibernateTemplate`是Spring框架中的一个类,位于`org.springframework.orm.hibernate3`包下。它提供了一系列简化Hibernate数据访问操作的方法,并且能够自动将Hibernate异常转换为Spring的数据访问异常体系中的...
问题 1:如果各层都不加事务管理的话,会报错 `org.springframework.dao.InvalidDataAccessApiUsageException`。 解决方案:在各层中添加 `@Transactional` 注解,例如: ```java @Transactional public void ...