Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction 异常一例
参考下面的文章,最终找到我的报错原因:
我是在 service中一个以 get开头的方法中,加入了一行数据库数据删除代码,因为
spring的事务配置中,配置了get开头的方法 是 readonle的:
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="count*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="list*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" read-only="true" />
所以导致了这个异常。
解决方法很简单,把这个方法重新起了个不是 以 get 开头的名字就解决了。
下面的文章仅供参考:
转:
[SSH] Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction
当执行到service层时,发生了如题的错误。
原因:
OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush mode
设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizationManager,使request的整个过程都使用同一个session,在请求过后再接除该sessionFactory的绑定,最后closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session。在这个过程中,若HibernateTemplate
发现自当前session有不是readOnly的transaction,就会获取到FlushMode.AUTOSession,使方法拥有写权限。也即是,如果有不是readOnly的transaction就可以由Flush.NEVER转为Flush.AUTO,拥有insert,update,delete操作权限,如果没有transaction,并且没有另外人为地设flush
model的话,则doFilter的整个过程都是Flush.NEVER。所以受transaction(声明式的事务)保护的方法有写权限,没受保护的则没有。
解决办法:在spring配置文件中加上这一部分
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="import*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED"/>
<!--这里如果觉着麻烦只要最后一行*就可以了,因为他会扫描所有的函数的 -->
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceOperation" expression="execution(* com.hdu.service.impl..*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
或者如果不想配置配置文件
,请在service层上面加上一个@Transactional
这样service层就加入了事务列,然后在所有的dao层中的写操作加一行getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
像下面这样
public void doCreateUser(Student student) {
getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
this.getHibernateTemplate().save(student);
}
Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction 异常一例的更多相关文章
- 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 ...
- ssh中的 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.
这个错误我整理了 半天才发现问题的存在. 尝试了网上的很多办法,但是最后都没有达到效果. 包括这两种: 第一种: web.xml种的配置 <filter> <filter-name ...
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
- HTTP Status 500 - 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.
如果在service类上面没有添加注解,出现异常 @Transactional
- 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.
解决办法, 再大dao的实现类上添加注解: @Transactional(readOnly = false ) 不让它只读就行了
- 解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fro问题
项目中碰到一个问题,就是将一个map转换成json格式的时候出现错误,最后排查将延迟加载关闭后成功转换,因为数据量较大,于是重新创建了一个对象进行接收. 解决办法是在配置文件中进行配置 虽然解决了这个 ...
- 增删改查 报异常org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readO
可能是Spring配置文件 事务通知里面的方法 与实际方法不匹配 <tx:advice id="advice" transaction-manager="tran ...
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnl
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
随机推荐
- 如何取得Oracle并行执行的trace
如何取得Oracle并行执行的trace: ALTER SESSION SET tracefile_identifier='10046_PROD';ALTER SESSION SET max_dump ...
- flask使用sqlit3的两种方式
方式一:raw_sql import sqlite3 from flask import Flask, request, jsonify app = Flask(__name__) DATABASE_ ...
- Hadoop日记Day15---MapReduce新旧api的比较
我使用hadoop的是hadoop1.1.2,而很多公司也在使用hadoop0.2x版本,因此市面上的hadoop资料版本不一,为了扩充自己的知识面,MapReduce的新旧api进行了比较研究. h ...
- JS计算混合字符串长度
用的是正则表达式 var str = ”坦克是tank的音译”; var len = str.match(/[^ -~]/g) == null ? str.length : str.length + ...
- PowerBI开发 第五篇:关系和交互
PowerBI 使用 内存的列式数据库 VertiPaq,用于对已发布的数据集进行数据压缩和快速处理,能够使PowerBI报表执行脱机访问,面向列的处理,高度优化对1:N关系的处理性能.关系是数据分析 ...
- 移动端效果之ScrollList
写在前面 列表一直是展示数据的一个重要方式,在手机端的列表展示又和PC端展示不同,毕竟手机端主要靠滑.之前手机端之前一直使用的IScroll,但是IScroll本身其实有很多兼容性BUG,想改动一下需 ...
- Jmeter(十二)_打印时间戳
Jmeter中提供了一种函数,可以打印时间戳,如下图 年: yyyy 月:MM 日:dd 时: HH 分: mm 秒:ss 关于时间戳的格式,可以自由组合定义,这里我写成这样 yyyy-MM-dd H ...
- 机器学习1—简介及Python机器学习环境搭建
简介 前置声明:本专栏的所有文章皆为本人学习时所做笔记而整理成篇,转载需授权且需注明文章来源,禁止商业用途,仅供学习交流.(欢迎大家提供宝贵的意见,共同进步) 正文: 机器学习,顾名思义,就是研究计算 ...
- DRF框架获取参数的方式
DRF获取参数的方式 例如url url(r'^demo/(?P<word>.*)/$', DemoView.as_view()) 在类视图中获取参数 url:http://127.0.0 ...
- 《大象Think in UML》阅读笔记(三)
Think in UML 阅读笔记(三) 把从现实世界中记录下来的原始需求信息,再换成一种可以知道开发的表达方式.UML通过被称为之概念化的过程来建立适合计算机理解和实现的模型,这个模型被称为分析模型 ...