Connection is read-only. Queries leading to data modification are not allowed
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
如上面配置,使用了spring的声明式事务管理数据库的事务,让所有的方法都加入事务管理,为了提高效率,可以把一些查询之类的方法设置为只读的事务。
例如有UserService的方法 listUsers, 获取所有用户,就没问题。但是如果是UserService的方法delUser, 要在dao层删除用户。就会报错误如下:
Connection is read-only. Queries leading to data modification are not allowed。
因此要添加下面的每一个add*,del*,update*等等。 分别给予访问数据库的权限。
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="clear*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
这种配置,对于增删改操作是非只读事务,但是对于查询等方法或者不需要事务的方法(*),设置成只读的事务。
还没有评论,来说两句吧...