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>

Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允的更多相关文章

  1. Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

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

    今天在做ssh项目开发的时候遇到一个问题,保存数据的时候报错: Write operations are not allowed in read-only mode (FlushMode.NEVER/ ...

  3. Write operations are not allowed in read-only mode

    使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVE ...

  4. 解决Hibernate Write operations are not allowed in read-only mode的方法

    错误信息: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed i ...

  5. Write operations are not allowed in read-only mode错误

    (转+作者个人理解) 最近在配置 Structs, Spring 和Hibernate整合的问题: 开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常: org ...

  6. org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode

    [spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowe ...

  7. hibernate框架学习错误集锦-org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL)

    最近学习ssh框架,总是出现这问题,后查证是没有开启事务. 如果采用注解方式,直接在业务层加@Transactional 并引入import org.springframework.transacti ...

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

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

随机推荐

  1. Python3玩转单链表——逆转单向链表pythonic版

    [本文出自天外归云的博客园] 链表是由节点构成的,一个指针代表一个方向,如果一个构成链表的节点都只包含一个指针,那么这个链表就是单向链表. 单向链表中的节点不光有代表方向的指针变量,也有值变量.所以我 ...

  2. NSOperation和NSOperationQueue的一些基本操作

    当初学习多线程这一块的时候,时间比较匆忙,没有细细考虑,而今重新学一次,算是复习和总结吧. #import "ViewController.h" @interface ViewCo ...

  3. ARKit从入门到精通(5)-ARScnView介绍

    转载:http://blog.csdn.net/u013263917/article/details/73156918 AR视图,在第一小节笔者介绍过,ARKit支持3D的AR场景和2D的AR场景,A ...

  4. 关于IIS下字体跨域问题

    将网站的CSS与项目分离后报了一个错,是因为字体跨域的原因,查了一下资料. 解决方案如下: 1:打开访问的资源iis,在HTTP 响应表头中添加代码名称:Access-Control-Allow-Or ...

  5. [转]【MySQL】关于时间的查询,比如本月,本年,本季度

    原文地址:https://www.cnblogs.com/flydkPocketMagic/p/7089324.html -- mysql查询本季度 -- 今天 select * from ticke ...

  6. VS2013代码调试:[7]如何避免调试时加载符号

    调试的时候不小心点了个东西,然后就花很长时间加在各种dll 解决办法: 1.点 调试2.然后 选项和设置3.右边勾上 启用源服务器支持4.左边点 符号5.把微软符号服务器勾6.运行的时候等一下 莫慌! ...

  7. [Note] Collaborator vs. the Factory

    Collaborator-vs-he-Factoryhtml, body {overflow-x: initial !important;}html { font-size: 14px; } body ...

  8. 【WPF/C#】图层筛选/拾取——Color Picker

    文章标题实在不懂怎么表述才清楚. 描述问题:多个图片(图层)重叠时,如何通过鼠标点击来拾取到相应的图层.因为图层中会有很多空白的地方(比如图片四周),要求是获取鼠标点击位置的像素颜色值,如果为空白时或 ...

  9. <要做股市赢家:杨百万>读书笔记

    书在这里 和这里: 要注意的是,并不是政府每出台一个政策股价就要变.如果听到各种消息,市场却没有反应,就不要去做这个聪明人.有消息后应该密切关注市场反应,看成交量.价格的变化等等,再作决定.总之,关键 ...

  10. PostgreSql 函数

    DECLARE curParkingTime TIMESTAMP ; curLeavingTime TIMESTAMP; parkingSpaceIndexCode VARCHAR[]; days I ...