Write operations are not allowed in read-only mode (FlushMode.MANUAL): 解决方法

成功解决InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMod 因为Jpa的EntityManageFactory会与Hibernate的SessionFactory造成事务冲突,所以需要在启动类上加上下面这个注解。 阅读详情
Messages: 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. 
 
File: org/springframework/orm/hibernate3/HibernateTemplate.java 
Line number: 1,175 


解决方法:

 

<!-- OpenSessionInViewFilter过滤器 -->
	<filter>
		<filter-name>openSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<!-- 解决read-only mode (FlushMode.NEVER/MANUAL) -->
		<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>


下面的内容参考:http://blog.csdn.net/tfy1332/article/details/8679711

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>

2024年ERP管理系统职业技能大赛软件测试赛项-测试报告 【说明本次测试的最终测试结果总结、测试过程中遇到的重要问题以及如何解决、被测系统的质量结论、个人的收获以及团队的得失等】【说明编写本测试报告的目的和实际读者】【说明本次测试实际人员安排及主要职责】【说明本次测试使用的测试用例设计方法】【说明本次测试使用的测试方法】【针对本次测试进行Bug汇总】【针对本次测试进行用例汇总】【说明本项目的背景情况】【说明本次测试的实际。 阅读详情

相关推荐

《联邦学习实战》杨强 读书笔记十四——构建公平的大数据交易市场

当数据具有资产属性之后,数据便可以直接或者间接地为公司、为社会创造价值和收益,并且可以作为一种特殊的商品在市场中进行交易。 与传统的商品交易相比,数据资产交易的市场前景更广阔,但同时也面临着很多的挑战,主要包括: 数据的质量、价格如何定义 在合法合规的前提下,数据的交易如何确保不会泄露用户的隐私 如何构建合理的激励机制来鼓励更多的参与方加入数据交易市场中 大数据交易 数据交易的定义 数据交易是指一种对数据进行买卖的行为,大数据交易由三方共同参与,分别为数据提供方、大数据交易平台和数据需求方:

IEEE802_11的博客 3455

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

用ssh时报错: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 ...

我的IT之旅 399

SPEI计算避坑指南:gma中Distribution和FitMethod参数怎么选?

本文深入探讨了在SPEI计算中如何科学选择gma库中的Distribution和FitMethod参数,帮助研究者避开常见陷阱。详细分析了LogLogistic、Gamma和Pearson3三种分布的适用场景,以及LMoment与MLE拟合方法的优缺点,为气象干旱研究提供实用指南。

weixin_30308101的博客 256

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 remo

彷徨de等待 3224

Python实战:用SkillMetrics库5分钟搞定泰勒图绘制(附完整代码)

本文详细介绍了如何使用Python的SkillMetrics库快速绘制专业泰勒图,以直观对比多个模型的预测性能。通过整合相关系数、标准差和中心化均方根误差三个核心指标,该工具能帮助数据科学家和研究者高效完成模型评估与可视化,提升分析报告质量。文章提供了从环境配置、数据准备到高级定制与子图对比的完整代码示例。

7z8x2c4v6b9的博客 376

第1.1节 构网型 vs. 跟网型:根本区别与技术原理

构网型与跟网型变流器的本质区别在于控制哲学与等效模型。跟网型变流器采用"电压跟随,电流注入"策略,等效为受控电流源,依赖电网电压作为参考,在弱电网下存在稳定性问题。构网型变流器采用"自主同步,电压构建"策略,等效为受控电压源,能主动构建电压和频率,具备自主运行、黑启动和电网支撑能力。两者的核心差异体现在同步机制、电网依赖性、故障行为和系统支撑等方面。构网型变流器更适合高比例新能源、弱电网和微电网场景,是未来电力系统的重要发展方向。

技术工作者 1415

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM

当在修改用户操作的时候出现错误: 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. 原因是:只读模式...

蟹蟹肉的博客 3265

大学计算 - NumPy库的矩阵运算 实训答案

本文介绍了三个NumPy矩阵操作的实验练习。第一关练习ndarray类型操作,包括矩阵构造、元素平方和计算、矩阵乘积运算和逆矩阵行列式计算;第二关针对matrix类型,涉及绝对值最大值获取、特定矩阵乘积运算和转置矩阵特征值计算;第三关实现Moore-Penrose伪逆矩阵计算,并与NumPy内置pinv函数结果比较误差。实验涵盖了NumPy核心矩阵操作,展示了从基础运算到高级矩阵分解的应用,帮助掌握科学计算中的矩阵处理技巧。

2403_89314916的博客 319

Write operations are not allowed in read-only mode (FlushMode.MANUAL) 的解决办法

问题描述:    近期根据需求架构了一个小型项目,由于是公司内部使用,没有考虑三高(即高并发、高可用、高扩展),所以使用了SSH(Spring\Struts\Hibernate)进行开发的,主体架构完成后,进行的第一个操作就遇到了一个问题,内容如下:org.springframework.dao.InvalidDataAccessApiUsageException: Write operation...

Spring Boot-Common On With You 8975

【博文汇总】I2C总线学习

将这一周学习I2C总线的文章汇总一下。 基础知识学习 触发器的建立时间和保持时间 如何学习总线技术 TTL电平和CMOS电平 深入理解 关于I2C和SPI总线协议 I2C总线深入浅出 I2C总线信号时序总结 对I2C总线协议的一些理解 对I2C总线的时钟同步和总线仲裁的深入理解 I2C总线学习终结,开始SPI总线的学习 深入理解IIC总线时序

ce123的技术博客 6219

【AI 赋能:Python 人工智能应用实战】16. BERT微调实战:中文新闻分类全流程(附模型蒸馏+ONNX部署完整代码)

中文新闻分类是NLP领域的经典实用任务,BERT模型凭借双向上下文建模能力,能有效解决中文歧义与长文本依赖问题,但存在推理速度慢、资源占用高的痛点。本文以THUCNews中文新闻数据集为核心,提供从数据预处理、BERT微调、模型蒸馏到生产部署的全流程实操指南。首先详解THUCNews的多编码读取与清洗(解决gbk/utf-8兼容问题);然后实现BERT微调,加入早停机制与混淆矩阵可视化,验证准确率达93.8%;接着用DistilBERT完成模型蒸馏,在仅损失0.6%准确率的前提下,将推理速度提升2.7倍。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1103

Write operations are not allowed in read-only mode (FlushMode.MANUAL)错误的解决方法

异常: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. 直到DaoIpml.java 都是正确的,

xinghuotianci的专栏 1648

ROSTEA软件下载及情感分析详细操作教程(附网盘链接)

原ROST虚拟团队出品的ROST系列文本内容挖掘分析平台,是辅助人文社会科学研究的免费计算平台。该软件可以实现文本预处理、分字、分词、词性识别、特殊名词抽取、词频统计、英文词频统计、情感计算、分类算法、聚类算法等一系列文本挖掘,是人文社科研究和论文写作的一把利器。该软件用户量超过一万人,遍布海内外100多所大学,包括剑桥大学、日本北海道大学、北京大学、清华大学、香港城市大学、澳门大学等众多高校。关于ROSTCM6的安装介绍可以参考之前的文章ROSTCM6软件下载及语义网络分析详细操作教程ROST EA。

m0_64336780的博客 1万+

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your的解决方法

禁止自动提交事务或执行SQL写操作(如INSERT/UPDATE/DELETE)。通过以上方法,可有效解决Hibernate只读模式下的写操作限制问题。,允许Hibernate自动同步数据到数据库。模式下,Session处于。在Spring项目中,使用。,则在写操作后手动调用。Hibernate的。注解声明事务,并指定。

小屁孩大帅-保密的博客 726

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)异常解决方法

发生如下异常: Write operations are not allowed in read-only mode(FlushMode.NEVER/MANUAL).. 解决方法,在web.xml里面的OpenSessionInViewFilter配置初始化参数,如下 hibernateFilter org.springframework.orm.hibernate3.suppor

wang623145708的专栏 1578

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Write operations are not allowed in read-only mode (FlushMode.MANUAL)异常解决的一种方法

[color=red][b]异常: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.[/b][/color...

iteye_5439的博客 160

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

spring mvc 事务管理 报错 Write operations are not allowed in read-only mode (FlushMode.MANUAL): 解决方法

转载 https://blog.csdn.net/violet_echo_0908/article/details/51084884 今天写代码的时候  遇到 Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into Flush 这个错误! 解决方案是添加 @Tra...

ittubaozi的专栏 2081

Write operations are not allowed in read-only mode (FlushMode.MANUAL)错误解决的一种方法

Write operations are not allowed in read-only mode (FlushMode.MANUAL)异常解决的一种方法异常:Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMM...

weixin_33708432的博客 187

错误: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 rem

吴静的blog 1万+

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)

在使用Spring+Hibernate或Spring+Hibernate+Struts进行增删改时会提示: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL) 分析原因如下: 在使用Spring+Hibernate或Spring+Hibernate+Struts的时候,会开启OpenSessi

JavaQ 3051

【SSH爬坑】Write operations are not allowed in read-only mode (FlushMode.MANUAL)

先说解决方法: 只需要在 SSH 项目的 Service 层加上 org.springframework.transaction.annotation.Transactional 包下的注解: @Transactional 问题就解决了 问题描述 ssh 项目操作数据库报错: Struts Problem Report Struts has detected an unhandled exception: Messages: Write operations are not allowed

CalledJoker的博客 1571

Code Recyclebin Contact me QQ:149906878 Write operations are not allowed in read-only mode (FlushMo

方法一: 遇到这个情况,我猜: 1、你一定使用的spring+hibernate 2、你一定在applicationContext.xml文件中写了事务配置如下: Xml代码       tx:advice id="txAdvice" transaction-manager="transactionManager">          tx:attributes>

pingpinggaga的博客 671

InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MA

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' mar...

EiletXie的博客 2347

解决Spring4+Hibernate4遇到的 Write operations are not allowed in read-only mode (FlushMode.MANUAL)

全部的错误stack类似: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove

sozdream的专栏 6816

错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..

使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决:        在没有使用Spring提供的Open Session In View情况下,因需要在service(or Dao)层里把session关闭,所以lazy loadin

yo^U^ng 9909

Write operations are not allowed in read-only mode (FlushMode.MANUAL) 错误解决

错误信息:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL):  Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnl...

qq_23124557的博客 1430
上一篇: Win 7 配置jdk 1.8 环境变量
下一篇: Spring声明式事务配置管理方法
JavaAlpha
博客等级 码龄18年 910粉丝 511原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址