关闭

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM

标签: session数据事务异常
266人阅读 评论(0) 收藏 举报
分类:

当我写数据的时候出现上面异常,查啊查,应该是保存数据时采用了默认的只读模式。

网上的方法配置事务:

1:

<!-- 定义事务管理 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- 配置事务异常封装 -->
   <bean id="persistenceExceptionTranslationPostProcessor" 
       class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

   <!--  声明式容器事务管理 ,transaction-manager指定事务管理器为transactionManager -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="get*" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <aop:config expose-proxy="true">
        <!-- 只对业务逻辑层实施事务 -->
        <aop:pointcut id="txPointcut" expression="execution(* com.zq.app.cms.service..*.*(..))" />
        <!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
        <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/>
    </aop:config>

2.修改默认只读模式:

<filter>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
      <init-param> -->
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</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 4.20 hibernate 4.3.10.Final

把 penSession()方法中 session.setFlushMode(FlushMode.MANUAL); 改为session.setFlushMode(FlushMode.AUTO);
结果是可以的。

0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

Hibernate4 事物解决问题

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read...
  • baidu_28283827
  • baidu_28283827
  • 2016-10-05 20:15
  • 2046

Oracle中su切换进去sqlplus登录失败的问题处理

问题描述:生产环境的oracle数据库突然登录不上去了,rlwrap生产环境的oracle数据库突然登录不上去了,rlwrap sqlplus "/ as sysdba"报错如下:rlwrap[ora...
  • mchdba
  • mchdba
  • 2015-01-16 20:51
  • 4374

ora-16433 重建控制文件恢复

11.2.0.3版本,非归档,大概是rm掉current的log,然后重建 controlfille后恢复导致一系列问题,并最终出现ora-600 2662错误,虽然这个错误很常见,但是你发现推进sc...
  • weiliu1463
  • weiliu1463
  • 2013-09-18 18:25
  • 4457

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM...
  • CSDNones
  • CSDNones
  • 2014-10-09 14:32
  • 1189

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read...
  • yu_maosheng
  • yu_maosheng
  • 2012-02-06 14:50
  • 946

(详解)Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session

昨天发现以前正常的功能报错了,错误日志如下: 报错日志: Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NA...
  • yuzongtao
  • yuzongtao
  • 2014-11-08 12:05
  • 5279

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

第一种解决办法 org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allo...
  • fax5201314
  • fax5201314
  • 2013-04-26 16:14
  • 1355

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

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read...
  • han_dongwei
  • han_dongwei
  • 2012-03-29 20:07
  • 1022

错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..

使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVE...
  • yongjiandan
  • yongjiandan
  • 2012-03-13 16:44
  • 9311

Write operations are not allowed in read-only mode (FlushMode.MANUAL):

在使用spring+hibernate进行数据update和delete时,出现了     org.springframework.dao.InvalidDataAccessApiUsageExce...
  • u013762572
  • u013762572
  • 2015-01-19 16:40
  • 711
    Java技术交流群:6128790
    微信
    编程技术学习交流群 :154514123
    微信
    个人资料
    • 访问:590133次
    • 积分:8283
    • 等级:
    • 排名:第2816名
    • 原创:311篇
    • 转载:34篇
    • 译文:2篇
    • 评论:110条
    最新评论