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

我是在 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. 分类-MNIST(手写数字识别)

    这是学习<Hands-On Machine Learning with Scikit-Learn and TensorFlow>的笔记,如果此笔记对该书有侵权内容,请联系我,将其删除. 这 ...

  2. Java技术——String类为什么是不可变的

    0. 前言   如果一个对象,在它创建完成之后不能再改变它的状态,包括对象内的成员变量.基本数据类型的值等等.那么这个对象就是不可变的.众所周知String类就是不可变的.转载请注明出处为SEU_Ca ...

  3. C++ 字符串, 数字 相互转化

    1: strL.Format("%x", 12); //将数字12转换成,16进制字符(C),存于strL 2: strH.Format("%x",12); / ...

  4. [CF1062F]Upgrading Cities[拓扑排序]

    题意 一张 \(n\) 点 \(m\) 边的 \(DAG\) ,问有多少个点满足最多存在一个点不能够到它或者它不能到. \(n,m\leq 3\times 10^5\) 分析 考虑拓扑排序,如果 \( ...

  5. 爱普生L313彩色打印相片

    操作环境: windows 和MAC 一.普通打印(默认选项) 1.爱普生L313 普通默认打印为快速不清晰打印. 2.以上打印效果出来图片比较快速出图,但是清晰度不够 二.照片打印设置 1.照片设置 ...

  6. 浅谈String模块ascii_letters和digits

    本文介绍string模块ascii_letters和digits方法,其中ascii_letters是生成所有字母,从a-z和A-Z,digits是生成所有数字0-9. 示例如下: In [2]: c ...

  7. flask入门小方法

    我是在pycharm中写的.那么需要在Termainal中cd 到当前文件所在的文件夹,在运行python py文件名 一开始想用面向对象的方法来封装这些小模块,但发现在面向对象中要用到类属性,以及类 ...

  8. WebGL模型拾取——射线法二

    这篇文章是对射线法raycaster的补充,上一篇文章主要讲的是raycaster射线法拾取模型的原理,而这篇文章着重讲使用射线法要注意的地方.首先我们来看下图. 我来解释一下上图中的originTr ...

  9. 用信鸽来讲解HTTPS的知识

    加密是一个很难理解的东西,这里头满是数学证明.不过,除非你是在开发一个加密系统,否则无需了解那些高阶的复杂知识. 如果你看这篇文章是为了创造下一个 HTTPS 协议,很抱歉,请出门左走,鸽子是远远不够 ...

  10. PAT甲题题解-1048. Find Coins (25)-水

    给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include < ...