zoukankan      html  css  js  c++  java
  • 执行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。 

    例如  

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

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

        <tx:method name="get*" read-only="false" />
  • 相关阅读:
    ADO.NET入门教程(五) 细说数据库连接池
    Delphi下使用指针的简单总结
    Delphi
    Delphi
    Delphi
    TXLSReadWriteII5 单元格读写
    [Delphi]Delphi开发的一些技巧
    TXLSReadWriteII2版本导出Excel文件:
    Tomcat使用startup启动,一闪而过,如何查看出错信息
    【转】Java保留固定小数位的4种方法
  • 原文地址:https://www.cnblogs.com/dashuai01/p/5085560.html
Copyright © 2011-2022 走看看