[Done]java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
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的更多相关文章
- java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
org.springframework.dao.TransientDataAccessResourceException: ### Error updating database. Cause: ja ...
- 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 描述:框架注入时候,配置了事物管理,权限设置 ...
- Connection is read-only. Queries leading to data modification are not allowed
看了下mysql-connector-5.1.40版本中,如果设置failoverReadOnly=true (即默认值,参考链接),当mysql连接failover时,会根据jdbc连接串将当前连接 ...
- 执行update操作的话,就会报“Connection is read-only. Queries leading to data modification are not allowed”的异常。
我用的是 spring + springmvc + mybatis +mysql. <tx:advice id="txAdvice" transaction-manager= ...
- 详细解读 :java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed,Java报错之Connection is read-only.
问题分析: 实际开发项目中,进行insert的时候,产生这个问题是Spring框架的一个安全权限保护方法,对于方法调用的事物保护,一般配置如下: <!-- 事务管理 属性 --> < ...
- Connection is read-only. Queries leading to data modification are not allowed 错误原因
因为我再spring 中使用了AOP进行事务管理,有如下配置 <tx:advice id="txAdvice" transaction-manager="trans ...
- 执行新增和修改操作报错connection is read-only. Queries leading to data modification are not allowed
出现这个问题的原因是默认事务只有只读权限,因此要添加下面的每一个add*,del*,update*等等. 分别给予访问数据库的权限. 方法名的前缀有该关键字设置了read-only=true,将其改为 ...
- java.sql.SQLException: connection holder is null;
一.问题来源分析 出现的错误 : Cause: java.sql.SQLException: connection holder is null; uncategorized SQLException ...
- java.sql.SQLException: connection holder is null 问题处理
问题描述 上上个周测试的时候突然报系统异常,于是我立即查看日志,发现是一个数据库异常:java.sql.SQLException: connection holder is null我第一想到的就是可 ...
随机推荐
- [转][Android] ListView中getView的原理+如何在ListView中放置多个item
ListView 和 Adapter 的基础 工作原理: ListView 针对List中每个item,要求 adapter “给我一个视图” (getView). 一个新的视图被返回并显示 如果 ...
- CAShapeLayer实现音量大小动态改变
我是效果图 实现如图这效果一般会直接通过多张图进行切换进行完成.但这样的处理,会浪费App的资源存储空间,而且效率也不高.那么今天我们用CAShapeLayer实现以下吧. 拆分: 1.一个椭圆 2. ...
- MAC 版本 phpstorm 配置 theme
mac 版本的配置文件在:./Library/Preferences/WebIde70/colors/ 将文件复制到这个目录中,然后phpStorm设置中,IDE设置->editor->f ...
- 通过手机音频口,实现与单片机通讯,做电子签名成功n
手机端的Ukey便携产品, 可以管理证书.加密解密.电子签名 : 1.通讯稳定,生成签名成功率100% 2.证书固化,私钥安全 3.走手机音频接口,通用.跨平台 4.耗电少,自带电池可长期供电,且可充 ...
- STM32 USB VBUS 监控
OTG_FS general core configuration register (OTG_FS_GCCFG) Bit 21 NOVBUSSENS: VBUS sensing disable op ...
- CMSIS-SVD Schema File Ver. 1.0
<?xml version="1.0" encoding="UTF-8"?> <!-- date: 07.12.2011 Copyright ...
- x-requested-with 请求头 区分ajax请求还是普通请求
在服务器端判断request来自Ajax请求(异步)还是传统请求(同步): 两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数 1.传统同步请求参数 accept t ...
- win10怎么彻底关闭自动更新
原文:https://jingyan.baidu.com/article/9faa7231e7b78b473c28cbb6.html 方法/步骤 1 单击左下角开始菜单点击设置图标进入设置界面 2 ...
- 在Windows上以服务方式运行 MSOPenTech/Redis
ServiceStack.Redis 使用教程里 提到Redis最好还是部署到Linux下去,Windows只是用来做开发环境,现在这个命题发生改变了,在Windows上也可以部署生产环境的 Redi ...
- 使用R语言和XML包抓取网页数据-Scraping data from web pages in R with XML package
In the last years a lot of data has been released publicly in different formats, but sometimes the d ...