1.异常分析

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.

大概意思就是:在只读模式(FlushMode.MANUAL)中不允许写操作,将您的会话转换为FlushMode.COMMIT/AUTO或从事务定义中删除“readOnly”标记。

2.分析原因:

<1>.事务通知相应方法设置属性,read-only="true"

  <tx:advice id="txadvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

此时dao层只可以执行,get,find,count(*)等查询操作,不可以执行cud 操作

<2>.事务通知了相应方法添加事务,但是aop管理设置时切入点表达式却不包含该方法 ,则其read-only 默认为 true

<!-- txadvice设置 --> 
<tx:advice id="txadvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>
<!--aop管理设置--> <aop:config>
<aop:pointcut expression="execution(* com.ssj..*.*())" id="myPointcut"/>//注意此处*.*()括号中为无参
<aop:advisor advice-ref="txadvice" pointcut-ref="myPointcut"/>
</aop:config>

注意:此处事务通知了所有方法添加事务,而切入点却只拦截了无参的方法.也就是说此时只有无参的构造方法是

可以进行cud操作的,而有参的则不能.

<3>.使用注解配置事务的时注解忘记添加也会抛出此异常

<4>.使用扫描添加注解的时候导致覆盖

例如:applicationContext.xml中com.ssj扫描全局添加注解之后,

  在springmvc.xml中又扫描一次com,ssj导致将applicationContext配置的事务覆盖,而且此配置文件中并没有相关事务的配置.从而出现此种异常

3.解决方案

针对原因一:将method 中read-only设置为false即可

针对原因二:将切入点表达式完善为:execution(* com.ssj..*.*(..)) 即可

针对原因三:在需要加事务的类上添加语句:

@Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED)

 注:在使用Spring代理时,默认只有在public可见度的方法的@Transactional 注解才是有效的,

  其它可见度(protected、private、包可见)的方法上即使有@Transactional 注解也不会应用这些事务属性的,Spring也不会报错,

  如果你非要使用非公共方法注解事务管理的话,可考虑使用AspectJ。

针对原因四:在springmvc.xml中配置扫描范围的时候不要涉及到applicationContext.xml中配置的事务设置范围

例如: applicationContext--->"execution(* com.ssj.service..*.*(..))" 给service包中的方法添加事务通知   注:使用@transaction注解时,同样

   springmvc.xml------><context:component-scan base-package="com.ssj.controller"></context:component-scan>

           开启注解扫描的时候不要涉及到service包中的方法,只管理controller即可

spring整合问题分析之-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.的更多相关文章

  1. 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.

    Struts Problem Report Struts has detected an unhandled exception: Messages: Write operations are not ...

  2. spring整合之后运行报什么只读错误。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.

    解决办法, 再大dao的实现类上添加注解: @Transactional(readOnly = false ) 不让它只读就行了

  3. ssh中的 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.

    这个错误我整理了  半天才发现问题的存在. 尝试了网上的很多办法,但是最后都没有达到效果. 包括这两种: 第一种: web.xml种的配置 <filter> <filter-name ...

  4. HTTP Status 500 - 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.

    如果在service类上面没有添加注解,出现异常 @Transactional

  5. 增删改查 报异常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 ...

  6. ssh整合思想 Spring分模块开发 crud参数传递 解决HTTP Status 500 - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or(增加事务)

    在Spring核心配置文件中没有增加事务方法,导致以上问题 Action类UserAction package com.swift.action; import com.opensymphony.xw ...

  7. Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnl

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

  8. Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn

    这个异常我在网上查看了很多资料,一般都说是hibernate的session问题,让重新两个方法,但是我以前用的时候没问题啊,所以一直找问题,终于这个bug让我找到了,就是因为我插入操作的时候用的是别 ...

  9. hibernate+spring整合增删改事务错误

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

随机推荐

  1. react-native在win10下用adb报错的解决方案

    react-native在WIN10上面运行用adb链接模拟器,会直接在powershell里报错, 报错大概意思是识别不了adb这个cmdlet函数. 找了很久的解决办法,直接找到adb.exe所在 ...

  2. NerdTree 学习

    http://www.jianshu.com/p/eXMxGx--------------来自大神到博客 到现在为止我仍然不能设置<F2>开启和隐藏目录树.sangxin.

  3. Java监听模式

    说明 生活中,监听无处不在.比如说,手机播放音乐功能,也是一种监听:你不点击播放按钮,手机就不放歌,当你点击时,手机就播放音乐.即触发某种行为,便执行相应的动作. 组成 Java监听模式右三个部分组成 ...

  4. Confusing Date Format UVALive 7711 给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。

    /** 题目:Confusing Date Format UVALive 7711 链接:https://vjudge.net/contest/174844#problem/A 题意:给定mm-mm- ...

  5. jsp页面form表单提交时候乱码

    1.问题描述: 表单提交中文乱码问题,怎么解决 2.原因 当表单传输到服务器上时,服务器会将传输的数据进行编码(iso-8859-1),然后当我们从服务器上面取数据的时候,就会出现乱码 3.解决的方式 ...

  6. 给jdk配置jvm的参数

    (1)window->preference->java->installed JREs ->edit  -Xms512m -Xmx512m -XX:MaxNewSize=512 ...

  7. 第二百二十六节,jQuery EasyUI,Tree(树)组件

    jQuery EasyUI,Tree(树)组件 本节课重点了解 EasyUI 中 Tree(树)组件的使用方法,这个组件依赖于 Draggable(拖 动)和 Droppable(放置)组件. 一.加 ...

  8. 在Intellij IDEA下用X-debug调试PHP

    用Intellij IDEA使用X-debug来调试PHP,主要需要配置的部分有三个地方,分别为php.ini的配置,IDEA的配置和浏览器的配置,主要如下: php.ini(wamp修改的是phpF ...

  9. Ubuntu修改默认root及密码

    Ubuntu的默认root密码是随 机的,即每次开机都有一个新的 root密码. 我们可以在终端输入命令 sudo passwd, 然后输入当前用户的密码,enter, 终端会提示我们输入新的密码并确 ...

  10. JavaScript 严格模式(use strict)

    前言: "use strict" 指令在 JavaScript 1.8.5 (ECMAScript5) 中新增. 它不是一条语句,但是是一个字面量表达式,在 JavaScript ...