Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允
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.问题:只读模式下(FlushMode.NEVER/MANUAL)写操作不被允许:把你的Session改成FlushMode.COMMIT/AUTO或者清除事务定义中的readOnly标记。
错误原因:
OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush
mode 设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizationManager,使request的整个过程都使用同一个session,在请求过后再接除该sessionFactory的绑定,最后closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session。在这个过程中,若HibernateTemplate
发现自当前session有不是readOnly的transaction,就会获取到FlushMode.AUTO
Session,使方法拥有写权限。也即是,如果有不是readOnly的transaction就可以由Flush.NEVER转为Flush.AUTO,拥有insert,update,delete操作权限,如果没有transaction,并且没有另外人为地设flush
model的话,则doFilter的整个过程都是Flush.NEVER。所以受transaction(声明式的事务)保护的方法有写权限,没受保护的则没有。
解决方法:
web.xml配置里添加
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<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>
如果在交给spring 管理的情况下,在beans.xml
里的配置
<bean
id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property
name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut
id="bussinessService"
expression="execution(*
com.fan.service.base.*.*(..))" />
<aop:advisor
pointcut-ref="bussinessService"
advice-ref="txAdvice"
/>
</aop:config>
<tx:advice
id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method
name="get*" read-only="false"
propagation="NOT_SUPPORTED"/>
<tx:method
name="find*" read-only="false"
propagation="NOT_SUPPORTED"/>
<tx:method
name="save*" propagation="REQUIRED"/> // 如果不把save
update delete都配置上,
<tx:method
name="update*"
propagation="REQUIRED"/> //这些操作会无效
<tx:method
name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允的更多相关文章
- Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
- 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 ...
- Write operations are not allowed in read-only mode错误
(转+作者个人理解) 最近在配置 Structs, Spring 和Hibernate整合的问题: 开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常: org ...
- 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 ...
- 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 ...
随机推荐
- PowerShell实现基于SharePoint的网站HomePage Auto-Upgrade Solution
*** Solution Auto-Upgrade Solution Tuesday, January 06, 2015 PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell ...
- 新的开始——LED灯汇编机器码的点亮方式
在几个月前看2440视频的时候,发现太多知识欠缺,购买开发板期间补习makefile,linux,arm汇编和arm构架之后,现在重新开始学习. 先看板子LED硬件连接图: 可以看到LED 1,2,4 ...
- RabbitMQ基础组件和SpringBoot整合RabbitMQ简单示例
交换器(Exchange) 交换器就像路由器,我们先是把消息发到交换器,然后交换器再根据绑定键(binding key)和生产者发送消息时的路由键routingKey, 按照交换类型Exchange ...
- 【转】Oracle 自定义函数语法与实例
原文地址:https://blog.csdn.net/libertine1993/article/details/47264211 Oracle自定义函数的语法如下: create or replac ...
- git的版本回退探索
简介 今天改完代码匆忙提交,上线发现有问题,那怎么办?废话,赶紧回滚,那怎么回滚,开始用git reset [--soft | --mixed | --hard 命令,但这命令真的能达到我预期的效果吗 ...
- 利用jQuery中live为动态生成Dom添加datepicker效果
利用Live属性,focus时重新绑定控件 $(".datepickerDom").live("focus", function () { $(this).da ...
- 学习MongoDB(二) Replica Set集群配置
1.官方网址:https://docs.mongodb.org/manual/tutorial/deploy-replica-set-for-testing/ 2.Replica Set介绍: htt ...
- Go Revel - Controllers(控制器)
Controller(控制器)整个revel都是围绕它处理所有请求 控制器可以是任何直接或间接内嵌了`*revel.Controller`类型的结构,如: type AppController str ...
- 主流HTML5游戏框架的分析和对比
本文主要选取了Construct2.ImactJS.LimeJS.GameMaker.CreateJS.lycheeJS.Crafty.three.js.melonJS.Turbulenz.Quint ...
- 【进阶修炼】——改善C#程序质量(3)
32, 总是优先考虑泛型. 泛型代码有很好的重复利用性,和类型安全性. 33, 应尽量避免在泛型类中声明静态成员. 静态成员达不到共享的目的.List<int>和List<Strin ...