zoukankan      html  css  js  c++  java
  • ### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are

    Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

    ; SQL []; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

    ### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
    ; SQL []; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
        at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
        at com.sun.proxy.$Proxy39.insert(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:253)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
        at com.sun.proxy.$Proxy52.saveV2(Unknown Source)

    在进行修改数据库的时候出现了这个异常
    很明显这个是只读引起的

    可是事实上我们的数据账号权限很高,说明不是权限问题,说明是事务问题了
    原因:你配置了只读事务
    解决办法:

    看下你的service层是否配置@Transactional(readOnly=true)
    如果上面你没有配置的话,那就是spring切面引起的
    

    在spring的配置文件中:

     <aop:config
      <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>
        </aop:config>
    
        <!-- 事务的传播特性 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="get*" propagation="REQUIRED" read-only="true"/>
            <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
            <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
        </tx:attributes>

    你是不是有类似于这样的,如果你的service方法名称是findpassword的话那么就会被拦截到了,然后就read-only了
    所以改一下你的方法名称吧


    或者在方法上添加注释
    @Transactional(readOnly = false)

  • 相关阅读:
    Symfony之入门学习
    git之fatal: Could not read from remote repository
    Class path contains multiple SLF4J bindings.
    php获取网址
    系统吞吐量(TPS)、用户并发量、性能测试概念和公式
    php tools 破解
    jQuery 图片裁剪插件 Jcrop
    php 上传文件 $_FILES['']['type']的值
    This is a bug I believe, and it took me 2-3 days to figure it out. Please do the following to get it working,
    curl_setopt — 设置 cURL 传输选项
  • 原文地址:https://www.cnblogs.com/llhl/p/9648638.html
Copyright © 2011-2022 走看看