2008-03-06
请教下spring的事务管理问题
刚使用SPRING,在程序中使用了事务管理。
下面是在SimpleService里调用的addError()方法,在2出产生的异常并没用回滚1处的数据,希望各位指导下哪里出了问题,谢谢
public void addError() throws Exception {
SimpleDao dao = new SimpleDao(getDataSource());
dao.addRightInfo();//1---插入正确记录
dao.addErrorInfo();//2---插入错误记录
PS:在dao中使用的是NamedParameterJdbcTemplate类操作数据,是否数据已经提交无法再回滚了?
下面是主要的配置
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="transactionInterceptorBeanGroup"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>simpleService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptorBeanGroup</value>
</list>
</property>
</bean>
<bean id="simpleService" class="test.SimpleService">
<property name="dataSource" ref="dataSource" />
</bean>
下面是在SimpleService里调用的addError()方法,在2出产生的异常并没用回滚1处的数据,希望各位指导下哪里出了问题,谢谢
public void addError() throws Exception {
SimpleDao dao = new SimpleDao(getDataSource());
dao.addRightInfo();//1---插入正确记录
dao.addErrorInfo();//2---插入错误记录
PS:在dao中使用的是NamedParameterJdbcTemplate类操作数据,是否数据已经提交无法再回滚了?
下面是主要的配置
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="transactionInterceptorBeanGroup"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>simpleService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptorBeanGroup</value>
</list>
</property>
</bean>
<bean id="simpleService" class="test.SimpleService">
<property name="dataSource" ref="dataSource" />
</bean>
评论
hotice
2008-03-06
ddandyy 写道
汗.......
建议你好好看看spring的手顺..........
3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对
只是下面那个bean那里定义的有问题 你没有把server声明成事务
建议你好好看看spring的手顺..........
3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对
只是下面那个bean那里定义的有问题 你没有把server声明成事务
你的意思是
<bean id="simpleService" class="test.SimpleService">
<property name="dataSource" ref="dataSource" />
</bean>
这里没有声明么,但<property name="beanNames">
<list>
<value>simpleService</value> </list>
</property>
是不是已经把这个bean纳入到事务管理了?不对的话麻烦举个例子哈,谢谢!
ddandyy
2008-03-06
汗.......
建议你好好看看spring的手顺..........
3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对
只是下面那个bean那里定义的有问题 你没有把server声明成事务
建议你好好看看spring的手顺..........
3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对
只是下面那个bean那里定义的有问题 你没有把server声明成事务
hotice
2008-03-06
zdllionheart 写道
你的异常被捕获了..
改了下,以前是直接抛出的Exception,是不是抛出特定异常才会回滚?
我这样设过,还是没办法回滚,谢谢
<bean name="transactionInterceptorBeanGroup"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED,PROPAGATION_SUPPORTS,-Exception</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,PROPAGATION_SUPPORTS,-Exception,-ServletException,-UncategorizedSQLException</prop>
</props>
</property>
</bean>
zdllionheart
2008-03-06
你的异常被捕获了..
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 99 次
- 性别:

- 来自: 大连

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
请教下spring的事务管理问 ...
ddandyy 写道汗....... 建议你好好看看spring的手顺..... ...
-- by hotice -
请教下spring的事务管理问 ...
汗....... 建议你好好看看spring的手顺.......... 3楼的 ...
-- by ddandyy -
请教下spring的事务管理问 ...
zdllionheart 写道你的异常被捕获了.. 改了下,以前是直接抛出的Ex ...
-- by hotice -
请教下spring的事务管理问 ...
你的异常被捕获了..
-- by zdllionheart






评论排行榜