码迷,mamicode.com
首页 > 编程语言 > 详细

Spring 实现部分事务回滚

时间:2017-07-19 23:31:23      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:get   cat   pre   readonly   ack   nal   需求   new   nsa   

例如有业务需求,在catch异常后,catch块内把异常的信息存入到数据库,而catch外的数据全部回滚

try {
  .......
   aaaService.save();
 
}catch(RuntimeException e) {

    bbbService.save(e.getMessage());
    throw new RuntimeException(e.getMessage());
}

 确保aaaService.save()的数据回滚,而 bbbService的save不回滚。

只能在bbbService save的头部加上开启新的事务即可

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class)

Spring 实现部分事务回滚

标签:get   cat   pre   readonly   ack   nal   需求   new   nsa   

原文地址:http://www.cnblogs.com/jqlbj/p/7208353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!