参考下面的文章,最终找到我的报错原因:

我是在 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

2016年12月13日 15:55:16 shawnMMM 阅读数:3092 标签: sshhibernate 更多

个人分类: sshhibernate
 
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mjl960108/article/details/53610578

当执行到service层时,发生了如题的错误。
原因:

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(声明式的事务)保护的方法有写权限,没受保护的则没有。

解决办法:在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 异常一例的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

  5. 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

  6. 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 ) 不让它只读就行了

  7. 解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fro问题

    项目中碰到一个问题,就是将一个map转换成json格式的时候出现错误,最后排查将延迟加载关闭后成功转换,因为数据量较大,于是重新创建了一个对象进行接收. 解决办法是在配置文件中进行配置 虽然解决了这个 ...

  8. 增删改查 报异常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 ...

  9. 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 ...

随机推荐

  1. mfc CProgressCtrl

    CProgressCtrl常用属性 CProgressCtrl类常用成员函数 CProgressCtrl代码示例 一.CProgressCtrl控件属性 当我们在处理大程序时,常常需要耗很长时间(比如 ...

  2. 未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage(转)

    版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking 本文版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显 ...

  3. idea 迁移maven项目出现导入仓库半天没反应的问题解决

    可以先参考: https://www.cnblogs.com/kinome/p/10289212.html 然后再看看maven配置文件是否正确,项目进行迁移时,如果环境不同,比如一个是使用的自定义m ...

  4. REST-framework快速构建API--权限

    我们在访问资源时,有些资源保密程度较高,需要特殊的人员才能访问.比如,获取公司的每日收入流水的API接口,只能CEO才能查看. 这时,我们就需要将资源设定权限了. REST-framework实现如下 ...

  5. 账户控制器(AccountController)

    账户控制器(AccountController) Account控制器提供了登录,注册,忘了密码和电子邮件激活页面功能. Layout模板视图 在Account视图文件夹中单独建设了模板文件: 登录页 ...

  6. NetBeans的(默认)快捷键

    NetBeans的(默认)快捷键 1.完成代码:ctrl+\ //任何地方按下此组合键,均会提示相应的参考字段:  2.错误提示:alt + enter //顾名思义,当系统报错时,按下此组合可以查看 ...

  7. Js_特效II

    字号缩放 让文字大点,让更多的用户看的更清楚.(也可以把字体变为百分比来实现)<script type="text/javascript">  function doZ ...

  8. python3绝对路径,相对路径

    from __future__ import absolute_import的作用: 直观地看就是说”加入绝对引入这个新特性”.说到绝对引入,当然就会想到相对引入.那么什么是相对引入呢?比如说,你的包 ...

  9. 一款基于Zigbee技术的智慧鱼塘系统研究与设计

    在现代鱼塘养鱼中,主要困扰渔农的就是养殖成本问题.而鱼塘养殖成本最高的就是养殖的人工费,喂养的饲料费和鱼塘中高达几千瓦增氧机的消耗的电费.实现鱼塘自动化养殖将会很好地解决上述问题,大大提高渔农的经济效 ...

  10. 第五次Scrum meeting

    第五次Scrum meeting 会议内容: 连接方面:确定封装成json的文本格式,尽量在满足在线组和手机客户端两组的情况下,降低自身的难度 测试方面:进行新一轮测试,主要测试程序的稳定性和可靠性, ...