InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode (FlushMode.NEV
来源:互联网 发布:linux jdk1.7下载 编辑:程序博客网 时间:2024/05/22 01:33
错误截图:
错误描述:
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.
尝试了以下三种方法
1、修改web.xml的配置,添加:flushMode为true
<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>mySessionFactory</param-value> </init-param> <init-param> <param-name> flushMode </param-name <param-value>AUTO</param-value> </init-param> </filter>
2、或者在spring_hibernate_cfg.xml配置文件中设置read-only=”false”
<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"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> </tx:attributes> </tx:advice>
3、或者在BaseDao的相应方法处添加
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW )
均没有解决该问题,如果项目较大的话,改配置文件影响很大,不建议用修改配置文件的方式进行处理,该问题最后找到的原因是:
在getXX()方法中调用了saveXX()方法,因为上层方法getXX()是只读的,所以在方法体内的方法都默认是只读的,即使saveXX()不是只读的也无效。
修改方式:将saveXX()的所有上层方法都修改为spring配置文件中拥有read-only=”false”方法名开头,例如:
配置文件:
<tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="check*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="exchange*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice>
则将方法getXX()更改为exchangeXX()就可以解决这个问题。
阅读全文
0 0
- InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode (FlushMode.NEV
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER)
- InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode
- [spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode
- 异常:InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode
- InvalidDataAccessApiUsageException 和 Write operations are not allowed in read-only mode 解决方法
- 错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- 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.NEVER/MANUAL)..
- Hibernate Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn
- 错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..
- 447. Number of Boomerangs
- GVIM 菜单乱码和内容乱码
- 常用的代码压缩工具
- 598. Range Addition II的C++解法
- 【剑指offer-解题系列(52)】构建乘积数组
- InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode (FlushMode.NEV
- Excel VBA高效办公应用-第二章-Excel VBA编辑基础-Part1(VBA关键字)
- Spring源码之XML解析
- python数据迁移--未完
- Android7.0中文文档(API)-- ViewAnimator
- Codeforces 814C An impassioned circulation of affection【Dp】
- bzoj 4802: 欧拉函数 大整数分解
- QT学习 常见操作记录
- JAVA发送http get/post请求,调用http接口、方法