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 ...
随机推荐
- 20155325 Exp8 Web基础
实验要求 (1).Web前端HTML(0.5分) 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. (2).Web前端javascipt(0 ...
- MFC 如何为控件关联变量
所关联的变量常见有两种,一种就是控件变量,一种就是数字变量. 为控件关联变量的方法也有两种,一种是通过软件工具添加,一种是手动添加代码. 软件工具添加,方便简单,但是根据软件的版本不同,以及不同的空间 ...
- SSIS 组件属性整理
整理SSIS 组件的属性解释及其用法 一,ExecValueVariable属性 有些Task组件执行完成之后,会产生输出结果,称作Execution Value,例如,Execute SQL Tas ...
- JQuery快速入门-Ajax
一.AJAX概述 概念:AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). 优点:通过在后台与服务器进行少量数据交换,AJAX ...
- 能帮我们学习吉他的音乐软件——Guitar Pro
Guitar Pro是一款十分好用的吉他软件,也是目前广大音乐爱好者最喜欢的多音轨的音谱编辑软件.支持MIDI.MusicXML.PTB.GTP等多种格式文件的导入/导出. Guitar Pro 7. ...
- aiohttp基本及进阶使用
客户端使用 发起请求 让我们从导入aiohttp模块开始: import aiohttp 好啦,我们来尝试获取一个web页面.比如我们来获取下GitHub的时间轴. async with aiohtt ...
- 11.5 Daily Scrum
请把现在当成11月5日······ Today's tasks Tomorrow's tasks 丁辛 餐厅列表数据结构设计 餐厅列表UI设计 李承晗 ...
- Daily Scrum NO.8
工作概况 今天是周六,虽然由于工作紧张要求这一日也定为工作日,但是也许是因为昨日大家工作做得较多或者周末的缘故,今天的进展状况并不理想.线程池和异常清理器的后端已经完成,而清理器的界面和动态爬取仍旧没 ...
- Linux内核分析作业 NO.4
扒开系统调用的三层皮(上) 于佳心 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-100002900 ...
- Linux实验报告
第一次链接: http://www.cnblogs.com/L1nke/p/4966820.html 第二次链接: http://www.cnblogs.com/L1nke/p/4992758.htm ...