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 ...
随机推荐
- spring filter 配置
web xml <filter> <filter-name>DelegatingFilterProxy</filter-name> <filter ...
- linux nexus bulid
1. 将下载好的nexus-2.5.1-bundle.tar.gz包,用FTP工具传至服务器上. 2. 解压安装包 解压命令: ? 1 tar -zvxf nexus-2.5.1-bundle ...
- mybatis中的.xml文件总结——mybatis的动态sql
resultMap resultType可以指定pojo将查询结果映射为pojo,但需要pojo的属性名和sql查询的列名一致方可映射成功. 如果sql查询字段名和pojo的属性名不一致,可以通过re ...
- Python 入门网络爬虫之精华版
Python 入门网络爬虫之精华版 转载 宁哥的小站,总结的不错 Python学习网络爬虫主要分3个大的版块:抓取,分析,存储 另外,比较常用的爬虫框架Scrapy,这里最后也详细介绍一下. 首先列举 ...
- Maven MyEclipse创建web项目没有src/maim/java
转载:http://blog.csdn.net/nich002/article/details/43273219 maven项目 错误: 找不到或无法加载主类 分类: java2015-01-29 ...
- 使用 Easy Sysprep v4(ES4) 封装 Windows 7教程
总:1.装系统ctrl+shift+f3(administrator)2.备份系统,快速备份(pe下)3.安装补丁,软件(系统下),不装安全类软件,需激活的软件重装后还要激活4.系统备份(pe下叠 ...
- [算法]谷歌笔试题:Beautiful Numbers
题目描述 思路 这道题就是在说,由多个1组成的数是beautiful的,现在想求出r进制中的r,使得给出的数字转换成r进制,得到beautiful的数字,如果有多种方式转换,那么取1的个数最多的那种情 ...
- 加密安装Kali Linux条件
加密安装Kali Linux条件安装Kali Linux到你的电脑过程很简单.首先你需要兼容的电脑硬件.最低硬件要求如下,更好的硬件性能会更好.i386镜象默认使用PAE内核,所以你能在大于4GB内存 ...
- ECS Linux服务器xfs磁盘扩容
ECS Linux服务器xfs磁盘扩 ECS Linux服务器xfs磁盘使用阿里云官方提供的磁盘扩容方法扩容会有报错: [root@iZ28u04wmy2Z ~]# e2fsck /dev/xvdb1 ...
- 【jquery】邮箱自动补全 + 上下翻动
最近在做通行证项目,里面注册模块有邮箱注册,需求方想要在输入 @ 后触发下拉框显示各个邮箱,效果如下: html 代码: <!DOCTYPE HTML> <html lang=&qu ...