Connection is read-only问题的产生原因与解决方法

    xiaoxiao2025-12-07  2

    WARN [org.hibernate.util.JDBCExceptionReporter] -<SQL Error: 0, SQLState: S1009> ERROR [org.hibernate.util.JDBCExceptionReporter] -<Connection is read-only. Queries leading to datamodification are not allowed> org.hibernate.exception.GenericJDBCException: could not executeupdate query 产生原因: 一般如果报了这个错,是项目中事务配置文件的问题。     <tx:advice id="txAdvice"transaction-manager="trans">               <tx:attributes>                       <tx:method name="init*"/>                       <tx:method name="insert*"/>                       <tx:method name="add*"/>                       <tx:method name="*"read-only="true"/>               </tx:attributes>       </tx:advice> 这里面规定了数据库操作函数必须要以以上字符串开头,否则的话就按照默认的配置,对数据库访问的权限为read-only。 一般来说一个数据库操作类XXService都是继承基类 DAO. 数据库操作类XXService中的方法在执行的时候,会和事务配置表中的进行对比,并赋给相应的权限。 解决办法: 解决方案有2种 1.规范命名 2.删除read-only="true",但是这种方法不推荐,因为有可能会出现一些你想不到的问题,或者是对服务器的性能造成影响。
    转载请注明原文地址: https://ju.6miu.com/read-1304710.html
    最新回复(0)