zoukankan      html  css  js  c++  java
  • javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

    解决办法:

    在执行service中一个方法bumenAuth()时出现错误:

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

    查看srping中事务管理配置:

    <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="find*">PROPAGATION_REQUIRED</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="create*">PROPAGATION_REQUIRED</prop> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="clear*">PROPAGATION_REQUIRED</prop> <prop key="build*">PROPAGATION_REQUIRED</prop> </props> </property> </bean>

    看了之后才知道,原来的事务策略的PROPAGATION_REQUIRED被删除后,bumenAuth()方法后忘了修改,所以导致报上述的错误

    修改方法一:

    将此方法修改为update或者build,add....等上述策略名称开头的方法:如:updateBumenAuth()

    修改方法二:

    增加PROPAGATION_REQUIRED即可

    修改方法三:

    将web.xml下的

    <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter>

    中的singleSession值修改为false,即不限制整个过程用同一个session,但缺点是Hibernate Session的Instance可能会大增,使用的JDBC Connection量也会大增,如果Connection Pool的maxPoolSize设得太小,很容易就出问题

  • 相关阅读:
    小程序 短信验证码 倒计时 变量作用域
    File syncing and sharing software with file encryption and group sharing, emphasis on reliability and high performance.
    图片合并与截断
    宽度分离
    无宽度准则
    linux系统/var/log目录下的信息详解
    Connection Phase Packets
    select version();desc mysql.user;
    mysql user password plugin
    Please read "Security" section of the manual to find out how to run mysqld as root!
  • 原文地址:https://www.cnblogs.com/ACMer/p/3178681.html
Copyright © 2011-2022 走看看