Transaction marked as rollback only: How do I find the cause

后端 未结 8 1666
深忆病人
深忆病人 2020-11-28 19:39

I am having issues with committing a transaction within my @Transactional method:

methodA() {
    methodB()
}

@Transactional
methodB() {
    ...
    em.pers         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 19:55

    I finally understood the problem:

    methodA() {
        methodB()
    }
    
    @Transactional(noRollbackFor = Exception.class)
    methodB() {
        ...
        try {
            methodC()
        } catch (...) {...}
        log("OK");
    }
    
    @Transactional
    methodC() {
        throw new ...();
    }
    

    What happens is that even though the methodB has the right annotation, the methodC does not. When the exception is thrown, the second @Transactional marks the first transaction as Rollback only anyway.

提交回复
热议问题