`
hotice
  • 浏览: 1491 次
  • 性别: Icon_minigender_1
  • 来自: 大连
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

请教下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>




分享到:
评论
4 楼 hotice 2008-03-06  
ddandyy 写道
汗.......
建议你好好看看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纳入到事务管理了?不对的话麻烦举个例子哈,谢谢!
3 楼 ddandyy 2008-03-06  
汗.......
建议你好好看看spring的手顺..........

3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对
只是下面那个bean那里定义的有问题 你没有把server声明成事务
2 楼 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>
1 楼 zdllionheart 2008-03-06  
你的异常被捕获了..

相关推荐

Global site tag (gtag.js) - Google Analytics