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

追查原因,查看切片事务配置如下:

查看源码:

初始化阶段-Step1:解析到xml配置,在RuleBasedTransactionAttribute中设置query*开发的方法的readOnly值为true

save等方法设置为fase:

运行阶段-Step1:(切片事务运行的逻辑大概简单说下:就是切点方法执行前会打开一个connection放在TransactionSynchronizationManager的threadLocal变量中,切点方法中第一个dao执行前则会创建应该session同样放在TransactionSynchronizationManager的threadLocal变量中,【TransactionSynchronizationManager】是一个比较核心的类,值得投入时间好好翻一下的,这个不展开讲了)

获取上面设置的readonly值

运行阶段-Step2:在切点方法执行前建立connection,此时根据配置设置连接只读:

并把只读状态设置进TransactionSynchronizationManager的threadLocal变量中,如下:

进而到>>

进而到>>

运行阶段-Step3:具体在运行时,connection进行数据库操作,如果这个连接是只读,就会报开头的错误。

解决方案:

本问题所在的业务场景是:查询一个核心的表,但是需求是需要记录这一次查询操作,这个方法是以query*开头,切片事务配置是connection只读,所以报了上面的错误。

最终的解决方法是,修改了方法名称,改为:saveLogAfterQuery*, 这样本问题得到了解决。

以上。

[Done]java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed的更多相关文章

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

    org.springframework.dao.TransientDataAccessResourceException: ### Error updating database. Cause: ja ...

  2. java最全的Connection is read-only. Queries leading to data modification are not allowed

    Connection is read-only. Queries leading to data modification are not allowed 描述:框架注入时候,配置了事物管理,权限设置 ...

  3. Connection is read-only. Queries leading to data modification are not allowed

    看了下mysql-connector-5.1.40版本中,如果设置failoverReadOnly=true (即默认值,参考链接),当mysql连接failover时,会根据jdbc连接串将当前连接 ...

  4. 执行update操作的话,就会报“Connection is read-only. Queries leading to data modification are not allowed”的异常。

    我用的是 spring + springmvc + mybatis +mysql. <tx:advice id="txAdvice" transaction-manager= ...

  5. 详细解读 :java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed,Java报错之Connection is read-only.

    问题分析: 实际开发项目中,进行insert的时候,产生这个问题是Spring框架的一个安全权限保护方法,对于方法调用的事物保护,一般配置如下: <!-- 事务管理 属性 --> < ...

  6. Connection is read-only. Queries leading to data modification are not allowed 错误原因

    因为我再spring 中使用了AOP进行事务管理,有如下配置 <tx:advice id="txAdvice" transaction-manager="trans ...

  7. 执行新增和修改操作报错connection is read-only. Queries leading to data modification are not allowed

    出现这个问题的原因是默认事务只有只读权限,因此要添加下面的每一个add*,del*,update*等等. 分别给予访问数据库的权限. 方法名的前缀有该关键字设置了read-only=true,将其改为 ...

  8. java.sql.SQLException: connection holder is null;

    一.问题来源分析 出现的错误 : Cause: java.sql.SQLException: connection holder is null; uncategorized SQLException ...

  9. java.sql.SQLException: connection holder is null 问题处理

    问题描述 上上个周测试的时候突然报系统异常,于是我立即查看日志,发现是一个数据库异常:java.sql.SQLException: connection holder is null我第一想到的就是可 ...

随机推荐

  1. Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题

    B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...

  2. BZOJ 4027: [HEOI2015]兔子与樱花 树上dp

    4027: [HEOI2015]兔子与樱花 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...

  3. centos 安装 redis

    1. 下载地址:$ wget http://download.redis.io/releases/redis-3.0.3.tar.gz 2. 解压缩$ tar -zvxf redis-3.0.3.ta ...

  4. ORACEL 创建表空间

    注意点: 1.如果在PL/SQL 等工具里打开的话,直接修改下面的代码中[斜体加粗部分]执行 2.确保路径存在,比如[D:\oracle\oradata\Oracle9i\]也就是你要保存文件的路径存 ...

  5. javascript 手机号间隔显示 123 4567 8910

    // 手机号分隔显示 let tel = this.data.tel_value // 原始手机号 let len = tel_value.length // 原始手机号的长度 let mobile ...

  6. apache 与 iis共存

    先装上了apache ,再装iis会出现错误.所以先关闭apache,再进行iis安装.iis安装完后修改iis80端口为8080端口, 同时使用命令 cd C:\Inetpub\AdminScrip ...

  7. USACO numtri 数塔问题

    /* ID:kevin_s1 PROG:numtri LANG:C++ */ #include <iostream> #include <cstdio> #include &l ...

  8. spm教程

    1.spm初学者教程:http://www.ernohermans.com/wp-content/uploads/2011/11/spm8_startersguide.pdf 2.spm官方mannu ...

  9. 解决:解压zip文件却变成cpgz文件

    众所周知,zip是一种压缩文件格式,MAC OS默认支持的文件格式,当时偶尔当你打开zip文件想要解压时,却自动变成了cpgz文件而没有解压,再双击这个cpgz文件,Archive Utility又会 ...

  10. 《jQuery技术内幕:深入解析jQuery架构设计与实现原理》

    <jQuery技术内幕:深入解析jQuery架构设计与实现原理> 基本信息 作者: 高云 出版社:机械工业出版社 ISBN:9787111440826 上架时间:2014-1-10 出版日 ...