Spring transaction: rollback on Exception or Throwable

前端 未结 4 2193
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 08:26

I wonder whether it makes sense to use instead of

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)

to use

4条回答
  •  旧巷少年郎
    2020-12-05 08:48

    Default value of rollback is register on Error Exception but when u register try{}catch{} manually it overriding the error, so in this case use

    catch {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
          }
    

    to do it manually or remove try catch

    also you may register exception type in transactional annotation such:

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    

提交回复
热议问题