执行update操作的话,就会报“Connection is read-only. Queries leading to data modification are not allowed”的异常。
我用的是 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”的异常。的更多相关文章
- java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
org.springframework.dao.TransientDataAccessResourceException: ### Error updating database. Cause: ja ...
- Connection is read-only. Queries leading to data modification are not allowed
看了下mysql-connector-5.1.40版本中,如果设置failoverReadOnly=true (即默认值,参考链接),当mysql连接failover时,会根据jdbc连接串将当前连接 ...
- [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 ...
- 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 错误原因
因为我再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 is read-only. Queries leading to data modification are not allowed,Java报错之Connection is read-only.
问题分析: 实际开发项目中,进行insert的时候,产生这个问题是Spring框架的一个安全权限保护方法,对于方法调用的事物保护,一般配置如下: <!-- 事务管理 属性 --> < ...
- 执行 update操作的时候有报错 ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> show full processlist; #查看问题的线程!!!! 找到异常进程的ID 然后kill 掉: mysql> kill xxxxxxx; #xxxxxx是ID ...
- Mysql执行Update操作时会锁住表
update tableA a,(select a.netbar_id,sum(a.reward_amt) reward_amt from tableB a group by a.netbar_id) ...
随机推荐
- Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breid ...
- CodeSmith使用总结--下拉列表和文件夹对话框属性
上一篇有点短了,因为实在没有什么可说的,这一篇会多一点.O(∩_∩)O~ 一.下拉列表 关于如何在CodeSmith中创建一个下拉列表的属性框其实很简单,是要使用C#中的枚举就行了,看操作. 首先定义 ...
- SQL 增加或删除一列
SQL 增加或删除一列 alter table tablename drop column columnname;alter table tabelname add columnname varcha ...
- OC基础 可变字典与不可变字典的使用
OC基础 可变字典与不可变字典的使用 1.不可变字典 1.1创建不可变字典 //创建字典 //注意: //1,元素个数是偶数 //2,每两个元素是一个键值对 //3,值在前,键在后 NSDiction ...
- poj3579 二分搜索+二分查找
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5468 Accepted: 1762 Descriptio ...
- 安装laravel
# 安装laravel 安装composer #安装 curl -sS https://getcomposer.org/installer | php #添加到PATH sudo mv compose ...
- Mysql学习(慕课学习笔记7)修改数据表(下)
添加主键约束 ALTER TABLE tb1_name ADD [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,…….) ...
- python——lambda
一lambda函数基础 1.lambda函数为匿名函数,即没有具体的函数名,而def函数创建的函数有函数名. >>> def foo(): return 'test' #命名为foo ...
- py2exe生成exe后,运行exe时提示No module named * 的解决办法
一个pymssql 的程序在解释器上运行正常,但是用py2exe打包后,提示 ImportError: No module named _mssql 百度了半天无果,然后bing,结果bing还是比百 ...
- Scala学习笔记--函数式编程
一.定义 简单说,"函数式编程"是一种"编程范式"(programming paradigm),也就是如何编写程序的方法论. 它属于"结构化编程&qu ...