복붙노트

[SPRING] @Transactional Annotation 속성의 우선 순위 / 상속

SPRING

@Transactional Annotation 속성의 우선 순위 / 상속

호출자 메서드 자체가 트랜잭션 인 경우 REQUIRED 전파의 경우에는 현재 메서드가 다른 트랜잭션 속성 (예 : rollbackFor)을 무시합니다.

그림 :

Class A {
    @Transactional(propagation = Propagation.REQUIRED,
        rollbackFor = { SomeException.class})
    void foo() {
        try {
           b.bar();
        } catch (OtherException e) {
           // is the transaction marked as rollback-only at this point ?
        }
    }
}

Class B {
    @Transactional(propagation = Propagation.REQUIRED,
        rollbackFor = { OtherException.class})
    void bar() {
        [...]
    }
}

편집하다 :

음, 나는 범위 응답에서 사소한 것을 피하고 싶습니다. 그래서 스프링 전파 처리에 대해 알고 있습니다.

그렇지 않다면 아래 문서의 관련 부분을 참조하십시오. 위 예제에 대한 첫 번째 부분을 명확히하고자합니다.

내 질문은 다음과 같이 표현할 수 있습니다.

논리적 트랜잭션 범위가 트랜잭션 속성을 보유합니까?

해결법

  1. ==============================

    1.그래서 저는 테스트 케이스를 설정했습니다. 짧은 대답은 '예'입니다.

    그래서 저는 테스트 케이스를 설정했습니다. 짧은 대답은 '예'입니다.

    트랜잭션 논리적 범위는 트랜잭션 등록 정보를 보유하며 그 경계는 실제로 주석 된 메소드입니다.

    따라서 기본 물리적 트랜잭션이 두 메소드 모두에서 동일하더라도 논리적 특성은 각 메소드에 적합하며 내부 메소드는 외부 메소드 트랜잭션의 롤백을 강제 실행할 수 있습니다. 마지막으로 커밋을 트리거하면 UnexpectedRollbackException이 발생합니다.

    cf. Spring TransactionInterceptor (주석은 내 것이다)

    try {
            retVal = invocation.proceed();
    }
    catch (Throwable ex) {
            completeTransactionAfterThrowing(txInfo, ex);
            throw ex;
    }
    

    completeTransactionAfterThrowing () :

    // txinfo is proper to the invocation target method
    if (txInfo.transactionAttribute.rollbackOn(ex)) {
                try {
                    txInfo.getTransactionManager().rollback(txInfo.getTransactionStatus());
                }
    

    AbstractPlatformTransactionManager.processRollback () :

    else if (status.isNewTransaction()) { //requiresnew
        doRollback(status);
    }
    else if (status.hasTransaction()) { //requiered
            [...]
            doSetRollbackOnly(status);
        }
    }
    
  2. ==============================

    2.봄 문서의 섹션 16.5.7을 참조하십시오. 내부 메소드는 트랜잭션 컨텍스트 내에서 호출 될 때 REQUIRED로 주석 처리 되더라도 동일한 실제 트랜잭션에 매핑됩니다.

    봄 문서의 섹션 16.5.7을 참조하십시오. 내부 메소드는 트랜잭션 컨텍스트 내에서 호출 될 때 REQUIRED로 주석 처리 되더라도 동일한 실제 트랜잭션에 매핑됩니다.

  3. ==============================

    3.사양에 대한 내 이해에서,이 예제에서 말하고 싶습니다 :

    사양에 대한 내 이해에서,이 예제에서 말하고 싶습니다 :

    Class A {
        @Transactional(propagation = Propagation.REQUIRED,
            rollbackFor = { SomeException.class})
        void foo() {
            try {
               b.bar();
            } catch (OtherException e) {
               // the transaction is marked as rollback-only by the inner call as it thrown an OtherException
               // XXX --- or not if inner logical scope does not handle overridden property 'rollbackFor' ? ---
               // anyway, we avoid UnexpectedRollbackException by enforcing physical rollback to outter scope programmatically, by throwing :
               throw new SomeExeption(e);
            }
        }
    }
    
    Class B {
        @Transactional(propagation = Propagation.REQUIRED,
            rollbackFor = { OtherException.class})
        void bar() {
            [...]
        }
    }
    

    따라서 재정의 된 "rollbackFor"속성은 내부 논리적 트랜잭션 범위 관리에 의해 처리됩니까?

    그런데 사용하는 정확한 트랜잭션 관리자 클래스 및 버전은 무엇입니까?

  4. from https://stackoverflow.com/questions/33277563/spring-transactional-annotation-properties-precedence-inheritance by cc-by-sa and MIT license