Connection is read-only. Queries leading to data modification are not allowe意思是只读



Connection is read-only. Queries leading to data modification are not allowe
中文意思:连接是只读的。查询导致修改数据不准
我的理解是:你要查询,可能是根据姓名来判断数据库表中是否存在这个人
[sql] view plaincopy
String sql = “select count(*) from table where name = ’123′”;

但是你在调方法的时候确是调用Update,实际上你是需要调用Query

解决办法:回去查看你的Dao->Impl层,换掉方法就ok!

Connection is read-only. Queries leading to data modification are not allowed
时间 2014-08-11 21:33:56 CSDN博客
原文 http://blog.csdn.net/u011067360/article/details/38498981
Connection is read-only. Queries leading to data modification are not allowed

<tx:advice id=”txAdvice” transaction-manager=”txManager”>
<tx:attributes>
<!– 让所有的方法都加入事务管理,为了提高效率,可以把一些查询之类的方法设置为只读的事务 –>

<!– method name=*, readonly=true表示所有的数据库操作都可以使用,但是只能是读取数据库。

例如有UserService的方法 listUsers, 获取所有用户,就没问题。

但是如果是UserService的方法delUser, 要在dao层删除用户。就会报错误如下:


Connection is read-only. Queries leading to data modification are not allowed。

因此要添加下面的每一个add*,del*,update*等等。 分别给予访问数据库的权限。

–>

<tx:method name=”*” propagation=”REQUIRED” read-only=”true” />
<!– 以下方法都是可能设计修改的方法,就无法设置为只读 –>

<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:attributes>
</tx:advice>
在上面的beans.xml配置中, 一开始没有配置add*,del*,update*等等。 就会在调用相应的方法时出错。

而获取数据则没有问题, 是因为有

<tx:method name=”*” propagation=”REQUIRED” read-only=”true” />
<pre name=”code” class=”html”><context:component-scan base-package=”com.eq3z” />
<!– 配置事务管理器 –>
<bean id=”transactionManager”
class=”org.springframework.orm.hibernate3.HibernateTransactionManager”>
<property name=”sessionFactory” ref=”sessionFactory” />
</bean>
<!– 配置事务传播特性 –>
<tx:advice id=”txAdvice” transaction-manager=”transactionManager”>
<tx:attributes>
<tx:method name=”save*” propagation=”REQUIRED”/>
<tx:method name=”update*” propagation=”REQUIRED”/>
<tx:method name=”delete*” propagation=”REQUIRED”/>
<tx:method name=”*” read-only=”true”/>
</tx:attributes>
</tx:advice>
<!– 定义使用事务管理的方法 –>
<aop:config>
<aop:pointcut id=”managerMethod” expression=”execution(* com.service.*.*(..))”/>
<aop:advisor pointcut-ref=”managerMethod” advice-ref=”txAdvice”/>
</aop:config>

http://blog.csdn.net/xb12369/article/details/8442103