我用的是 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. HTML与CSS入门——第十四章  使用边距、填充、对齐和浮动

    知识点: 1.在元素周围添加边距的方法 2.在元素中添加填充的方法 3.对齐的方法 4.float属性的使用 这里提到了CSS禅意花园,这块有时间可以玩玩~ margin和padding:用于添加元素 ...

  2. 使用游标循环进行SQL更新插入的SQL语句

    使用SQL中的循环,可以实现许多我们需要的操作,比如SQL更新操作.下面就为您介绍使用游标循环进行SQL更新插入的SQL语句写法,希望对您深入学习SQL更新有所帮助. --开始事务 BEGIN TRA ...

  3. 点击<a>标签,禁止页面自动跳到顶部的解决办法

       最近在开发一个小web的时候想给一个按钮增加一个弹出dialog功能,但是发现点击按钮后页面总是自动滚动至顶部,这点从用户体验上来讲是极其不爽的,于是开始跳进google大池寻求解决办法.网上的 ...

  4. (二)CodeMirror - 配置项

    theme: string theme:'monokai' 引入对应的css, <link rel="stylesheet" href="../theme/mono ...

  5. 新建一个vs2010的MFC工程

    1.在新建mfc工程时Visual C++下的MFC MFC ActiveX Control用来生成MFC ActiveX控件程序 MFC Application用来生成MFC应用程序. MFC DL ...

  6. Go学习笔记(二):编写 HelloWorld 程序

    //Hello.go代码 package main import "fmt" func main(){ fmt.Printf("Hello, world!This is ...

  7. Mysql学习(慕课学习笔记5)约束

    约束类型: 1.NOT NULL (非空约束) 2.PRIMARY KEY(主键约束) 每张数据表只能存在一个主键 主键保证记录的唯一性 主键自动为NOT NULL (Auto_increment  ...

  8. 【GNOME 边框】GNOME窗口无边框

    今天我新装了一台LINUX UBUNTU12.10,顺手就把UNITY换成了GNOME,但是发现边框消失. 大概原因:metacity 不同版本配置之间的冲突. 解决办法:删除home目录下的旧配置文 ...

  9. hdu 1599 find the mincost route

    http://acm.hdu.edu.cn/showproblem.php?pid=1599 floyd找最小环. #include <cstdio> #include <cstri ...

  10. 关于在C#中实现AOP 拦截编程模式的新的探索

    前面有篇文章,是从其他个人博客中贴过来的.地址:http://www.lanhusoft.com/Article/240.html 作者总结实现的挺好. 但是.不能不考虑性能!!使用 ContextB ...