[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. html页面docutype前面出现字符会导致IE678 margin:0 auto;失效

    html页面<!DOCTYPE html>前面出现字符会导致IE678 margin:0 auto;失效

  2. ubuntu 13.04 root权限设置方法详解

    很多朋友安装升级Ubuntu 13.04之后不知道ubuntu 13.04 root权限设置的具体方法,今天这篇文章就将为大家详细介绍设置root权限的步骤,新手朋友可以来看一看哦~ Ubunto 1 ...

  3. GoF的23个经典设计模式

    以文本和思维导图的方式简明扼要的介绍了GoF的23个经典设计模式,可当成学习设计模式的一个小手册,偶尔看一下,说不定会对大师的思想精髓有新的领悟. GoF(“四人帮”,又称Gang of Four,即 ...

  4. 从Eclipse里导出Android程序到手机里

    参考自:http://wenku.baidu.com/view/e28bb57c1711cc7931b716a7.html

  5. ListVIew中插入view

    public class MainActivity extends Activity { private ListView listview; private List<String> d ...

  6. WebSocket实时异步通信

    WebSocket实时异步通信 [一]WebSocket简介 WebSocket是HTML5推出一个协议规范,用来B/S模式中服务器端和客户端之间进行实时异步通信. 众所周知,传统的HTTP协议中,服 ...

  7. matlab——sparse函数和full函数(稀疏矩阵和非稀疏矩阵转换)

    函数功能:生成稀疏矩阵 使用方法 :S = sparse(A) 将矩阵A转化为稀疏矩阵形式,即矩阵A中任何0元素被去除,非零元素及其下标组成矩阵S.如果A本身是稀疏的,sparse(S)返回S. S ...

  8. Win7下简约的Gif查看器 仅1.8M

    win7下面由于版权的原因把,默认打开gif的是ie浏览器,这个多么的不方便呀,我在网上淘到了这个程序,话说是从Xp中提取移植过来的.用起来很不错. 下载地址在: http://pan.baidu.c ...

  9. [记录]使用setTimeout实现不同时间进行切换文本的颜色

    开始使用的是setinterval(),但是setinterval()的time是固定的,假如我想改变time,就需要每次clearInterval()一次. 如: setInterval(funct ...

  10. app测试点

    手机上的app分为基于HTML5的app(类似于pc上的b/S应用)和本地app(类似于C/S结构). 所以测试上我们也可以充分吸收web的b/s和c/s测试经验.但是不同于pc上的应用测试,手机上的 ...