spring things Management (@Transactional), abnormal transaction rollback, try catch capture not throw, things do not roll back

By default, spring affairs only happen when the uncaught RuntimeException rollback (a runtime exception).
Note, do not write and write try catch try {} catch (Exception e) {throw new RuntimeException ();} is the same meaning.
The figure below shows abnormal java system:
Here Insert Picture Description
Solution:

  1. Not capture, capture or throw RuntimeException;
  2. Capture and manually rolled back,
        try {
            //orderDOMapper.insertSelective(orderDO);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
            //throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR,"重复秒杀!");
        }

For the general user experience is good, I want to throw exceptions custom, will use the second solution, capture, and then manually rolled back, and then throw an exception customize.

Guess you like

Origin blog.csdn.net/weixin_44997483/article/details/92571083