Spring transaction REQUIRED vs REQUIRES_NEW : Rollback Transaction

前端 未结 2 468
青春惊慌失措
青春惊慌失措 2021-01-29 23:38

I have a method that has the propagation = Propagation.REQUIRES_NEW transactional property:

@Transactional(propagation = Propagation.REQUIRES_NEW)
p         


        
2条回答
  •  时光取名叫无心
    2021-01-30 00:07

    If you really need to do it in separate transaction you need to use REQUIRES_NEW and live with the performance overhead. Watch out for dead locks.

    I'd rather do it the other way:

    • Validate data on Java side.
    • Run everyting in one transaction.
    • If anything goes wrong on DB side -> it's a major error of DB or validation design. Rollback everything and throw critical top level error.
    • Write good unit tests.

提交回复
热议问题