Jose Ignacio Gil Jaldo opened SPR-9375 and commented

I am not sure if it is intended to be a new feature or it is a bug, but since the @Transactional annotation is annotated as well as @Inherited, I would say it's more like a bug.

The situation is the following:

  • Interface I
  • Class A (abstract has JPA implementation methods, implements I).
  • Class B (concrete and extending the class A) wants to take advantage of those methods.

There are more than 1 TransactionManager (one per module).

If I annotate the class B with @Transactional and try to use qualifier (to specify which transaction manager I want to use), it does not work. The problem seems to be in the class: AbstractFallbackTransactionAttributeSource in this snippet to be more specific:

// Second try is the transaction attribute on the target class.
txAtt = findTransactionAttribute(specificMethod.getDeclaringClass());
if (txAtt != null) {
    return txAtt;
}

there are 2 options, the comment is wrong or the code is wrong. specificMethod.getDeclaringClass() is not the target class in my situation, is my abstract class A (because that one implements the methods).

A solution would be adding:

// Second try is the transaction attribute on the target class.
txAtt = findTransactionAttribute(userClass);
if (txAtt != null) {
    return txAtt;
}

Because that one would search in both userClass and specificMethod.getClass() since the annotation is @Inherited. It should be backwards compatible (except on the strange case of someone setting an annotation on both parent and child and expecting the one of the parent to be used, so the child one's would be 100% useless).


Affects: 3.1 GA

Reference URL: https://github.com/spring-projects/spring-framework/pull/106

1 votes, 3 watchers

Comment From: spring-projects-issues

Chris Beams commented

Hi Jose,

Since you've already gone so far as suggesting a fix here, would you be willing to submit the change (and a unit test, of course) as a pull request? Check out the contributor guidelines for instructions how to do this.

Thanks!

Comment From: spring-projects-issues

Jose Ignacio Gil Jaldo commented

Hi Chris,

I just pulled a patch for it. Let me know your thoughts.

Kind regards, PS: sorry for doing it only now

Comment From: spring-projects-issues

Chris Beams commented

pull request at: https://github.com/SpringSource/spring-framework/pull/105

Comment From: spring-projects-issues

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Comment From: elab

The problem is unfortunately still not solved. How to reuse inherited methods using
the same current transaction manager?

Related: #14295