Skip to content

@Transactional of the target class is not considered for methods defined in a superclass #32492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,18 @@ protected TransactionAttribute computeTransactionAttribute(Method method, @Nulla
// If the target class is null, the method will be unchanged.
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);

// First try is the method in the target class.
// First try is the method in the declaring class.
TransactionAttribute txAttr = findTransactionAttribute(specificMethod);
if (txAttr != null) {
return txAttr;
}

// Second try is the transaction attribute on the target class.
txAttr = findTransactionAttribute(specificMethod.getDeclaringClass());
Class<?> specificTargetClass = method.getDeclaringClass();
if (targetClass != null) {
specificTargetClass = ClassUtils.getUserClass(targetClass);
}
txAttr = findTransactionAttribute(specificTargetClass);
if (txAttr != null && ClassUtils.isUserLevelMethod(method)) {
return txAttr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void labelsAreApplied() {
}

/**
* Test that transaction attribute is inherited from class
* Test that transaction attribute is inherited from class declaring the method
* if not specified on method.
*/
@Test
Expand All @@ -189,6 +189,17 @@ void defaultsToClassTransactionAttribute() {
new NoRollbackRuleAttribute(IOException.class)));
}

/**
* Test that transaction attribute is inherited from the target class
* if not specified on method.
*/
@Test
void defaultsToTargetClassTransactionAttribute() {
TransactionAttribute actual = getTransactionAttribute(TestBean4.class, TestBean12.class, "getAge");
assertThat(actual).satisfies(hasRollbackRules(new RollbackRuleAttribute(Exception.class),
new NoRollbackRuleAttribute(IOException.class)));
}

@Test
void customClassAttributeDetected() {
TransactionAttribute actual = getTransactionAttribute(TestBean5.class, "getAge");
Expand Down Expand Up @@ -932,4 +943,9 @@ public int getAge() {
}
}


@Transactional
static class TestBean12 extends Empty {
}

}