[spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode

org.springframework.dao.InvalidDataAccessApiUsageException: Write

operations are not allowed in read-only mode

(FlushMode.NEVER/MANUAL): Turn your Session into

FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction

definition.

at

org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOper

ationAllowed(HibernateTemplate.java:1095)

这个异常产生的主要原因是DAO采用了Spring容器的事务管理策略,如果操作方法的名称和事务策略中指定的被管理的名称不能够匹配上,spring 就会采取默认的事务管理策略(PROPAGATION_REQUIRED,read only).如果是插入和修改操作,就不被允许的,所以报这个异常

查看spring中事务管理配置:

<bean id="txProxyTemplate" abstract="true"

class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager">

<ref bean="transactionManager" />

</property>

<property name="transactionAttributes">

<props>

<prop key="find*">PROPAGATION_REQUIRED</prop>

<prop key="save*">PROPAGATION_REQUIRED</prop>

<prop key="remove*">PROPAGATION_REQUIRED</prop>

<prop key="update*">PROPAGATION_REQUIRED</prop>

<prop key="create*">PROPAGATION_REQUIRED</prop>

<prop key="add*">PROPAGATION_REQUIRED</prop>

<prop key="del*">PROPAGATION_REQUIRED</prop>

<prop key="clear*">PROPAGATION_REQUIRED</prop>

<prop key="build*">PROPAGATION_REQUIRED</prop>

</props>

</property>

</bean>

看了之后才知道,原来的事务策略的<prop key="*">PROPAGATION_REQUIRED</prop>被删除后,bumenAuth()方法后忘了修改,所以导致报上述的错误

修改方法一:

将此方法修改为update或者build,add....等上述策略名称开头的方法:如:updateBumenAuth()

修改方法二:

增加<prop key="*">PROPAGATION_REQUIRED</prop>即可

修改方法三:

将web.xml下的

<filter>

<filter-name>OpenSessionInViewFilter</filter-name>

<filter-class>

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

</filter-class>

<init-param>

<param-name>singleSession</param-name>

<param-value>true</param-value>

</init-param>

</filter>

中 的singleSession值修改为false,即不限制整个过程用同一个session,但缺点是Hibernate Session的Instance可能会大增,使用的JDBC Connection量也会大增,如果Connection Pool的maxPoolSize设得太小,很容易就出问题

参考:关于OpenSessionView(http://liuwei1578.blog.163.com/blog/static/4958036420092104215514/)

Spring事务配置TransactionProxyFactoryBean(http://liuwei1578.blog.163.com/blog/static/49580364200921041136625/)

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode的更多相关文章

  1. hibernate框架学习错误集锦-org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL)

    最近学习ssh框架,总是出现这问题,后查证是没有开启事务. 如果采用注解方式,直接在业务层加@Transactional 并引入import org.springframework.transacti ...

  2. 增删改查 报异常org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readO

    可能是Spring配置文件 事务通知里面的方法  与实际方法不匹配 <tx:advice id="advice" transaction-manager="tran ...

  3. javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  4. OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException

    报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r ...

  5. org.springframework.dao.InvalidDataAccessApiUsageException

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  6. org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

    题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后 ...

  7. org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案

    异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identi ...

  8. org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案

    1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...

  9. Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法

    1.错误信息 Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUs ...

随机推荐

  1. mysql事务问题

    mysql事务: 若mysql 开启事务后START TRANSACTION ,不显示提交commit,则默认自动回滚,而不是默认自动提交.

  2. C# 之 获取文件名及拓展名

    1.用Path类的方法(最常用) string fullPath = @"\WebSite\Default.aspx"; string filename = System.IO.P ...

  3. servlet案例

    1.重定向 方式1:在servlet中写:response.setStatus(302);      response.setHeader("Location","路径& ...

  4. android开发之路03

    一.Activity1.如何在一个应用程序中定义多个Activity:①定义一个类,继承Activity:②在该类当中,复写Activity当中的onCreate方法:③在AndroidManifes ...

  5. selendroid inspector xpth元素定位记录

    android自动化测试元素定位,目前发现appium官方的uiautomatorviewer一般的元素定位还行,但好多都找不到. 这个时候,可以考虑selendroid的inspector 官网:h ...

  6. iOS Core Animation学习总结(3)--动画的基本类型

    一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...

  7. ios--socket

    一.打开服务器 a.在终端打开,到服务器文件路径输入命令 python chatserver.py b.当显示 Iphone Chat server started 表示成功 二.建立连接 a.设置对 ...

  8. Dubbo在Spring和Spring Boot中的使用

    一.在Spring中使用Dubbo 1.Maven依赖 <dependency> <groupId>com.alibaba</groupId> <artifa ...

  9. Redis多机集群

    Redis集群.网上很多教程,只是按着它的步骤来做只能在单机上跑,而已不有点抗.也不用密码验证 开始: 1:redis集群最少需要要6个服务器端,因此先搞6台虚拟机 我用 centOS-7 mini ...

  10. 07_XPath_01_入门

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...