我用的是 spring + springmvc + mybatis +mysql、

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="select*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="get*" read-only="true" />
</tx:attributes>
</tx:advice>

让所有的方法都加入事务管理,为了提高效率,可以把一些查询之类的方法设置为只读的事务

<!-- method name=*, readonly=true表示所有的数据库操作都可以使用,但是只能是读取数据库

但是如果是UserService的方法delUser, 要在dao层删除用户。就会报错误如下:

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

出现这个问题的原因是默认事务只有只读权限,因此要添加下面的每一个add*,del*,update*等等。 分别给予访问数据库的权限。

还有就是在service层中在只有只读权限的方法中调用操作数据库的方法也会报错Connection is read-only. Queries leading to data modification are not allowed。

例如

 public String getXX(){
server.updateXX(obj);
}

例如在get方法中调用了update方法但是get只有只读权限,所以需要修改方法名或者将配置文件修改为

    <tx:method name="get*" read-only="false" />

执行update操作的话,就会报“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. Connection is read-only. Queries leading to data modification are not allowed

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

  3. [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 ...

  4. 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 描述:框架注入时候,配置了事物管理,权限设置 ...

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

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

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

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

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

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

  8. 执行 update操作的时候有报错 ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

    mysql> show full processlist; #查看问题的线程!!!! 找到异常进程的ID 然后kill 掉: mysql> kill xxxxxxx; #xxxxxx是ID ...

  9. Mysql执行Update操作时会锁住表

    update tableA a,(select a.netbar_id,sum(a.reward_amt) reward_amt from tableB a group by a.netbar_id) ...

随机推荐

  1. 原生js获取body

    1. doucumnet.body 2. document.getElementsByTagName("body")[0]

  2. Java性能漫谈-数组复制之System.arraycopy

    当我还年幼的时候,我很任性,复制数组也是,写一个for循环,来回倒腾,后来长大了,就发现了System.arraycopy的好处. 为了测试俩者的区别我写了一个简单赋值int[100000]的程序来对 ...

  3. 外观模式-facade实现interface的方式(简单工厂+facade组合使用)

    Façade 外观模式 1.Façade实现为interface的具体过程 在Façade.java 接口 工厂 将构造方法私有  static 方法产生一个工厂 此时 客户端不知道 Façade的存 ...

  4. 简单的批量读取外部insert文并插入DB

    package com.tongxiang.item.base.dao; import java.io.BufferedReader; import java.io.File; import java ...

  5. mysql-cluster集群原理介绍和搭建步骤(四个data/sql节点) (转)

    MySQL簇概述 MySQL簇是一种技术,该技术允许在无共享的系统中部署“内存中”数据库的簇.通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求.此外,由于每个组件有自己的内存和磁盘, ...

  6. UVA 10791 Minimum Sum LCM

    唯一分解定理 把n分解为 n=a1^p1*a2^p2*...的形式,易得每个ai^pi作为一个单独的整数最优. 坑: n==1     ans=2: n因子种数只有一个     ans++: 注意溢出 ...

  7. sqlserver exists和in 与exists和not in

    1.exists 和 in 1.1 正常情况下exists和in的效果是一样的,如图试验 即使子查询中包含null也没有关系,依然可以正常使用 1.2 in 和 exists效率比较 先看in 由图中 ...

  8. IOS 项目问题总结

    把自己项目中遇到的问题总结一下,供大家参考,希望大家多多提出意见!! 在Xcode 6.2中遇到Your build settings specify a provisioning profile w ...

  9. 膜拜一个神奇的女人——Hedy Lamarr

    她演绎了首部露点电影.经历了六次婚姻.出版了首本自曝隐私的自传,还曾入室行窃过两次——在这样一个饱受争议的大环境下,她还能在60多年前提出“跳频”技术和一系列无线信号技术的全新概念,其中,“跳频”技术 ...

  10. smartassembly 使用指南

    原文 http://www.cnblogs.com/hsapphire/archive/2010/09/21/1832758.html smartassembly 提供了一种用于优化和混淆你的 .ne ...