[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我第一想到的就是可 ...
随机推荐
- Unity UGUI之Image
Image组件在Inspector Source Image--需要一个Sprite(精灵). Color--图片的颜色 Material--可以添加材质球 RayCast Target--选中可以传 ...
- sklearn中的超参数调节
进行参数的选择是一个重要的步骤.在机器学习当中需要我们手动输入的参数叫做超参数,其余的参数需要依靠数据来进行训练,不需要我们手动设定.进行超参数选择的过程叫做调参. 进行调参应该有一下准备条件: 一个 ...
- CentOS6永久修改主机名称
1.修改network vi /etc/sysconfig/network 修改HOSTNAME值 2.修改hosts vi /etc/hosts 修改中间的那个localhost 3.使用hostn ...
- SQl CASE 语句的嵌套使用方式
case具有两种格式.简单case函数和case搜索函数. 1.简单case函数 case sex when ’1’ then ’男’ when ’2’ then ’女’else ’其他’ end ...
- JS 判断PC、android、ios、微信浏览器
1.通过js userAgent来判断 <h1>判断访问此链接的操作系统</h1> <script> var Agents = new Array("An ...
- Android SDK最小需求
As a minimum when setting up the Android SDK, you should download the latest tools and Android platf ...
- gdb 调试的信息输出到文件
# (gdb) set logging file <文件名> # (gdb) set logging on # (gdb) thread apply all bt # (gdb) set ...
- dtrace for mysql
http://dtrace.org/blogs/brendan/2011/06/23/mysql-performance-schema-and-dtrace/
- mogodb优化
http://snoopyxdy.blog.163.com/blog/static/6011744020157511536993/ http://www.csdn.net/article/2012-1 ...
- 辛星跟您解析在CSS面包屑中三角形的定位问题
刚才看到有位网友非常纳闷第二个棕色三角形是怎么定位的,我当感觉在以下说不清楚,就特别开了一片博客.来说清楚它.首先,前面的代码我们先抄下来,至于前面这部分代码是怎么来的,读我的用CSS制作面包屑导航的 ...