2008-05-23
从Spring MVC-step-by-step发现的问题(Spring 2.5.2)
关键字: sping
Spring2.5.2的MVC-step-by-step教程没有一点问题,按照它的步骤,能够创建一个完整的Spring的Demo.只是,教程里用的数据库是HSQL,当把HSQL换成我本地的MySQL5的时候,出现了问题。
这个异常是在对产品价格update时出现的:
在网上查了一下,说是事务配置的问题,找到教程里面关于事务配置的地方:
对这一部分的解释是:The pointcut applies to any method called on the ProductManager interface. The advice is a transaction advice that applies to methods with a name starting with 'save'. The default transaction attributes of REQUIRED applies since no other attribute was specified. The advice also applies "read-only" transactions on any other methods that are adviced via the pointcut.
大概翻译一下:切面是针对实现ProductManager接口的类的。对以'save'开头的方法的建议是事务建议,因为没有指定属性,所以使用默认的'REQUIRED'属性;对其他方法使用'read-only'事务。
看来,这个配置也没什么问题了;我猜,还是MySql的connector的问题(mysql-connector-java-5.0.8-bin.jar),MySql5在事务方面还是不太稳定。最后,把配置文件中这行<tx:method name="*" read-only="true"/>删除,就没问题了。
这个异常是在对产品价格update时出现的:
root cause java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1552) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504) org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102) org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:795) org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:588) org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:789) org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:812)...
在网上查了一下,说是事务配置的问题,找到教程里面关于事务配置的地方:
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<aop:config>
<aop:advisor pointcut="execution(* *..ProductManager.*(..))" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="save*"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
对这一部分的解释是:The pointcut applies to any method called on the ProductManager interface. The advice is a transaction advice that applies to methods with a name starting with 'save'. The default transaction attributes of REQUIRED applies since no other attribute was specified. The advice also applies "read-only" transactions on any other methods that are adviced via the pointcut.
大概翻译一下:切面是针对实现ProductManager接口的类的。对以'save'开头的方法的建议是事务建议,因为没有指定属性,所以使用默认的'REQUIRED'属性;对其他方法使用'read-only'事务。
看来,这个配置也没什么问题了;我猜,还是MySql的connector的问题(mysql-connector-java-5.0.8-bin.jar),MySql5在事务方面还是不太稳定。最后,把配置文件中这行<tx:method name="*" read-only="true"/>删除,就没问题了。
- 17:04
- 浏览 (514)
- 评论 (3)
- 分类: Java/JavaEE
- 相关推荐
评论
sherman4223
2008-07-21
回复
仅删除<tx:method name="*" read-only="true"/>是不够的,save方法没有将increase后的数据保存在数据库里。
这样改了就好了
/*
int count = getSimpleJdbcTemplate().update(
"update products set price = ? where id = ?",
new MapSqlParameterSource().addValue("price", prod.getPrice())
.addValue("id", prod.getId()));
*/
int count = getSimpleJdbcTemplate().update( "update products set price = ? where id = ?",
prod.getPrice(),prod.getId() );
这样改了就好了
jianfeng008cn
2008-05-24
回复
汗一个 教授派的吧
发表评论
我的相册
2008-08-05_213302
共 15 张
共 15 张
最新评论
-
JavaFX初识
呵呵,Netbean和Eclipse不相上下,我觉得差远了!对于FX我更加看好F ...
-- by skzr.org -
《奇迹的黄昏》,一本反思 ...
Thank you so much.
-- by 华少少华 -
四国军棋界面Swing/AWT的 ...
厉害。我先下了,多谢.
-- by woairenyunli -
[zt]“牛奶倒海”和“房产 ...
虽然也出现了次级债这类开发商靠集资机构多方盈利的猫腻,但是从资本操作意愿来讲,还 ...
-- by 叶子 -
旅途中的行骗模式
刚好今天我也在看这本书,哈哈
-- by climber2002







评论排行榜