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. python导外部包

    win7+python2.7下安装spark 最近在学习Spark,由于我的Python是在windows下安装的,好多库也已经配置好,所以需要将spark安装在windows环境下,下面是安装过程: ...

  2. [转]Tomcat启动报错:AnnotationConfigBeanDefinitionParser are only available on JDK 1.5 and higher

    原文地址:https://blog.csdn.net/daochuwenziyao/article/details/54949151 问题描述: 控制台输出AnnotationConfigBeanDe ...

  3. iPad适合写作吗

    我一直感觉对着电脑不利于思考,当需要纯粹的思考时,我习惯让视线离开屏幕,起身走动两圈,再用纸和笔整理思路,想清楚后,开始动手编码. 双手端着iPad时,似乎也能有类似纸与笔的组合效果,大脑能适应那种界 ...

  4. hive表增量抽取到oracle数据库的通用程序(一)

    hive表增量抽取到oracle数据库的通用程序(二) sqoop在export的时候 只能通过--export-dir参数来指定hdfs的路径.而目前的需求是需要将hive中某个表中的多个分区记录一 ...

  5. Android指南 - 样式和主题

    本文翻译自:https://developer.android.com/guide/topics/ui/themes.html Style和theme词汇是专用术语,下文直接使用而不翻译. 样式和主题 ...

  6. ECS Linux服务器xfs磁盘扩容

    ECS Linux服务器xfs磁盘扩 ECS Linux服务器xfs磁盘使用阿里云官方提供的磁盘扩容方法扩容会有报错: [root@iZ28u04wmy2Z ~]# e2fsck /dev/xvdb1 ...

  7. 三篇文章了解 TiDB 技术内幕——说计算

    在这我们将关系模型简单理解为 Table 和 SQL 语句,那么问题变为如何在 KV 结构上保存 Table 以及如何在 KV 结构上运行 SQL 语句. 假设我们有这样一个表的定义: CREATE ...

  8. 获取checkbox的选中的值

    var arr = new Array(); var idsObj = $("input [name='ids']"); for(var i=0;i<idsObj.lengt ...

  9. 关于css定位

    关于定位要弄清一个概念,那就是"文档流" 什到是文档流 说得简单一点 就是 自上而下 从左到右 生成顺序 关于html元素又分为两种 块状元素 内联元素 块状元素:单独占一行 内联 ...

  10. JSP之Cookie对象使用

    1.写入Cookie //如果用户勾选一个月内自动登录,则将信息保存至Cookie String[] strings=request.getParameterValues("autoLogi ...