最近公司一个老项目,更新数据库报这个错误。一般是方法名字不对(配置里面设置了,比如说,方法名字中带有get的,不让修改数据)。
<aop:config <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/> </aop:config> <!-- 事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" read-only="true"/> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> </tx:attributes>
<aop:config <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>
</aop:config> <!-- 事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<tx:method name="query*" propagation="REQUIRED" read-only="true"/> </tx:attributes>
比如说上面这种配置,就是方法里面包含有get、find、query的(以这个开头的),就会默认你是查询,如果你这个方法其实是更新数据,那就报错了。所以解决办法就是,如果你是更新数据的方法,那就不要出现get、find、query,另外起一个别的名字。