[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我第一想到的就是可 ...
随机推荐
- bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式
2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- 内功心法 -- java.util.LinkedList<E> (4)
写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------下文主要对java.util ...
- leetcode644. Maximum Average Subarray II
leetcode644. Maximum Average Subarray II 题意: 给定由n个整数组成的数组,找到长度大于或等于k的连续子阵列,其具有最大平均值.您需要输出最大平均值. 思路: ...
- Java中文件与字节数组转换
注:来源于JavaEye 文件转化为字节数组: http://www.javaeye.com/topic/304980 /** * 文件转化为字节数组 * * @param file * @retur ...
- HDU 4496 D-City (并查集,水题)
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- 分享我用Taker做任务时需要的各种资源的精华帖,方便查阅
http://tieba.baidu.com/p/2310764470 第一名 [Tasker论坛] https://groups.google.com/group/tasker/?pli=1http ...
- 关于npm run build 卡住不动的坑。。。
起因:最近开发个项目使用的vue,有些功能需要生产版本放服务器上测试,这就出问题了..卡住了,不动了,还不报错 这是在vscode的终端里面,试了git hash,试了cmd , 试了powershe ...
- c#面试3(选择题)
1.下列有关基本类的大小不正确的是 A.int类型是4个字节 B.bool类型是1个字节 C.long类型是8个字节 D.char类型是一个字节 3.有关数组说法不正确的是 A.数组的内存是分配在栈中 ...
- Ext各种对话框
<HTML> <HEAD> <TITLE>选择确认对话框</TITLE> <link rel="stylesheet" typ ...
- iOS:UIPageViewController翻页控制器控件详细介绍
翻页控制器控件:UIPageViewController 介绍: 1.它是为我们提供了一种类似翻书效果的一种控件.我们可以通过使用UIPageViewController控件,来完成类似图书一样的翻页 ...