您的位置:首页 > 编程语言 > Java开发

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

2016-08-15 18:07 453 查看
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",但是这种方法不推荐,因为有可能会出现一些你想不到的问题,或者是对服务器的性能造成影响。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 事务配置