Write operations are not allowed in read-only mode错误
(转+作者个人理解) 最近在配置 Structs, Spring 和Hibernate整合的问题:
开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常:
org.springframework.dao.InvalidDataAccessApiUsageException错误
但是在我们开启OpenSessionInViewFilter这个过滤器的时候FlushMode就已经被默认设置为了MANUAL!
如果FlushMode是MANUAL或NEVEL,在操作过程中 hibernate会将事务设置为readonly,所以在增加、删除或修改操作过程中会出现如下错误:
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 from transaction definition; 解决办法1:
直接修改OpenSessionInViewFilter过滤器的配置,配置过滤器的时候配置就是在一般的配置里面加上下面蓝色部分就可以了,直接指定flushMode的配置就OK了:
下面是配置文件:(web.xml)
[html] view plaincopyprint?
<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> 解决方法2:
就是配置事务的边界,在你方法的执行时配置事务边界!
下面是sessionFactor.xml配置:
[html] view plaincopyprint?
<!-- 事务的配置 --> <!-- sessionFactory 为自己配置 sessionFactory 的 bean--> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <!-- execution(public * *.*.*..*.*(..)) 为自己项目中操作数据库中的方法 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- name 为 方法名 --> <tx:method name="**" read-only="true" /> <tx:method name="**" propagation="REQUIRED"/> </tx:attributes> </tx:advice> 下面是总结:
原理:因为配置openSessionInView时,启动后他默认是给没有配置 事务的加强处理(包括注解型事务) 的方法都默认为只读的,所以在插入数据时就会报上面的错
Write operations are not allowed in read-only mode错误的更多相关文章
- Write operations are not allowed in read-only mode (FlushMode.NEVER/
今天在做ssh项目开发的时候遇到一个问题,保存数据的时候报错: Write operations are not allowed in read-only mode (FlushMode.NEVER/ ...
- Write operations are not allowed in read-only mode
使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVE ...
- 解决Hibernate Write operations are not allowed in read-only mode的方法
错误信息: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed i ...
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode
[spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowe ...
- hibernate框架学习错误集锦-org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL)
最近学习ssh框架,总是出现这问题,后查证是没有开启事务. 如果采用注解方式,直接在业务层加@Transactional 并引入import org.springframework.transacti ...
- 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 ...
- Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
- 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 ...
- Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
随机推荐
- iOS多线程的初步研究(七)-- dispatch对象
谈起iOS的dispatch(正式称谓是Grand Central Dispatch或GCD),不得不说这又是iOS(包括MacOSX)平台的创新,优缺点这里不讨论,只有当你使用时才能真正体会到.我们 ...
- js正则表达式用法大全
匹配中文字符的正则表达式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^x00-xff] 评注:可以用来计算字符串的长度(一 ...
- 14.spark RDD解密
开篇:spark各种库,sparksql,sparkmachicelearning,等这么多库底层都是封装的RDD.意味着 1:RDD本身提供了通用的抽象, 2:spark现在有5个子框架,sql,S ...
- 299. Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...
- 一个n位的数,去掉其中的k位,问怎样去使得留下来的(n-k)位数按原来的前后顺序组成的数最小
例如 8314925去掉4个数,留下125最小,注意有前后顺序要求,要是没有顺序当然是123. 解决方案 贪心算法,在每次被访问的位置保证有最优解. 思路一 分析:求一共n位,求其中的m位组成的数最小 ...
- WebMvcConfigurerAdapter
spring Boot 默认的处理方式就已经足够了,默认情况下Spring Boot 使用WebMvcAutoConfiguration中配置的各种属性. 建议使用Spring Boot 默认处理方式 ...
- POJ 1322 Chocolate(母函数)
题目链接:http://poj.org/problem?id=1322 题意: 思路: double C[N][N]; void init() { C[0][0]=1; int i,j; for(i= ...
- JSON格式化 JSON美化 输出到html
{"promotion_details":{"promotion_detail":[{"discount_fee":"22.20& ...
- 总结Selenium自动化测试方法(二)测试环境搭建
(接上期内容) 二.测试环境搭建 1.安装python 现在python3.0比python2.0多了一些改进的功能(详见http://zhidao.baidu.com/link?url=3sT1g7 ...
- Ajax的简单请求案例
$.ajax({ url : rootPath +'/jasframework/choosepilecontrol/querySubsytem.do', type : "POST" ...