spring2.0事务的嵌套

Spring2.0事务嵌套详解
本文详细解析了Spring2.0环境下如何实现事务的嵌套处理,通过具体示例介绍了ServiceA与ServiceB之间的交互及事务回滚机制。

spring2.0事务的嵌套:

一个ServiceA:

public class ServiceA{

public int transactionDetailService(PaymentDetail detail)
   throws ServiceException {
  try {
     return dao.deletePaymentDetail(detail);
  } catch (DAOException ex) {
   logger .error("错误发生在:PaymentDetailServiceImpl.deletePaymentdetailService()方法中!");
   throw new ServiceException();
  }
 }

}

另一个ServiceB:

public class ServiceB{

public int deletePaymentInfoService(int payId) throws ServiceException {
  try {
         PaymentDetail detail = new PaymentDetail();
         detail.setPayId(payId);
          paymentDetailService.transactionDetailService(detail);
         dao.deletePaymentInfo(payId);     //如果这里执行删除操作失败的话,那么ServiceB的事务回滚,同时,内嵌事务ServiceA的事务也回滚;即transactionDetailService()中的删除操作回滚。
        return 1;
      } catch (DAOException ex) {
   logger.error("错误发生在:PaymentInfoServiceImpl.deletePaymentInfoService(int payId)方法中!");
   throw new ServiceException();
    }
 }

}

Spring2.0 配置文件:

 <aop:aspectj-autoproxy />

 <!-- default define, uses transactionManager,default *  is readonly -->
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="insert*" />
   <tx:method name="update*" />
   <tx:method name="*" read-only="true" />
   <tx:method name="transaction*" propagation="NESTED" />
  </tx:attributes>
 </tx:advice>
 <aop:config proxy-target-class="true">
  <aop:advisor
   pointcut="execution(* com.ving.xzfw.service.impl.*Service*.*(..))"
   advice-ref="txAdvice" />
 </aop:config>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值