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 ...
随机推荐
- 第21章 RTX 低功耗之睡眠模式
低功耗是 MCU 的一项非常重要的指标,比如某些可穿戴的设备,其携带的电量有限,如果整个电路消耗的电量特别大的话,就会经常出现电量不足的情况,影响用户体验. 本章节为大家讲解 M3/4的低功耗方式之睡 ...
- Jenkins + Django 完整实战,细化到每一步操作
Reference: http://blog.csdn.net/GitChat/article/details/78271099?locationNum=3&fps=1 [不要错过文末彩蛋] ...
- NewStyleClass学习笔记[一]
from : https://www.python.org/doc/newstyle/ New-style Classes Unfortunately(遗憾,不幸的), new-style class ...
- ARKit从入门到精通(5)-ARScnView介绍
转载:http://blog.csdn.net/u013263917/article/details/73156918 AR视图,在第一小节笔者介绍过,ARKit支持3D的AR场景和2D的AR场景,A ...
- 纯真ip导入mysql
先从纯真官网右侧下载ip数据库 更新后,点击解压,可以把数据库保存为txt格式 格式化数据 ip格式如下图 可见并不是很规范,而且最底部字段数也不一致 先用正则表达式,查找替换一下 (\d+.\d+. ...
- python 获取有关访问者的浏览器的 细节
检测访问者的浏览器和版本号有关访问者的浏览器的更多信息有关访问者的浏览器的全部细节根据浏览器来提醒用户 <html><body><script type="te ...
- [转]JS组件系列——表格组件神器:bootstrap table
原文地址:https://www.cnblogs.com/landeanfen/p/4976838.html 前言:之前一直在忙着各种什么效果,殊不知最基础的Bootstrap Table用法都没有涉 ...
- Android学习笔记(38):Handler消息传递处理机制
先说为什么须要Handler: Android的主线程又叫UI线程,用于处理与UI相关的时间.Android仅仅同意在主线程中改动UI组件,当我们在其它线程中须要改动UI界面时.就须要发送消息到主线程 ...
- mysqldump具体应用实例
1.导出整个数据库 mysqldump -h主机 -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -h127.0.0.1 -u wcnc -p smgp_apps ...
- 腾讯云CentOS 安装 Hadoop 2.7.3
1.安装 jdk yum install java 2.安装maven wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.0/binar ...