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)

  • 相关阅读:
    Lambda表达式 For Android
    RxJava重温基础
    Asp.Net Core 依赖注入默认DI,Autofac注入
    Asp.Net Core2.0 基于QuartzNet任务管理系统
    Asp.Net Core 基于QuartzNet任务管理系统(这是一篇用来水的随笔)
    ADO.NET通用类库
    TripleDES加密解密
    ASP.NET Core的身份认证框架IdentityServer4--(4)添加第三方快捷登录
    ASP.NET Core的身份认证框架IdentityServer4--(3)令牌服务配置访问控制跟UI(可自定义路由)添加
    ASP.NET Core的身份认证框架IdentityServer4--(2)API跟WEB端配置
  • 原文地址:https://www.cnblogs.com/llhl/p/9648638.html
Copyright © 2011-2022 走看看