Skip to content
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

Doc: Inheritance of @Transactional and lookup behaviour of AbstractFallbackTransactionAttributeSource [SPR-12474] #17080

Closed
spring-projects-issues opened this issue Nov 26, 2014 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process

Comments

@spring-projects-issues
Copy link
Collaborator

Ravi Sanwal opened SPR-12474 and commented

Lets start with a question to the expert.
Consider a service(or repo) bean

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * A service class with transactional method
 */
@Service
public class ServiceBean implements ServiceInterface {
    @Transactional
    public void serviceMethodA() {}
    public void serviceMethodB() {}
}

And a subclass of it

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Extended {@link ServiceBean}
 */
@Service
@Transactional
public class MagicalServiceBean extends ServiceBean {
}

Notice that only one method of ServiceBean is marked @Transactional while MagicalServiceBean has a class level @Transactional declaration.

What should be the transactional nature of method serviceMethodB when it is called on an injected (and proxied et al.) instance of MagicalServiceBean?

Apparently as per the apidocs of org.springframework.transaction.interceptor.AnnotationTransactionAttributeSource (org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource) we expect to get a transactional serviceMethodB.

Abstract implementation of TransactionAttributeSource that caches attributes for methods and implements a fallback policy: 1. specific target method; 2.target class; 3. declaring method; 4. declaring class/interface.

A specific distinction is mentioned between target class and declaring class/interface

Codewise if we look at org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource.getTransactionAttribute(Method, Class<?>), the targetClass parameter points to MagicalServiceBean.class.

You may consider it as a documentation defect.
There could be arguments for both "should apply transactional on extended method"(because this seems more intuitive and correct) and "should not apply on extended method"(to keep it the way base class has defined and because we can always create a delegate method on the extended class if we need to make it transactional)

Regardless this seems to be an odd behavior to me.


Affects: 4.1.2

@spring-projects-issues
Copy link
Collaborator Author

Ravi Sanwal commented

So, is it really a documentation thing? Would you, if possible, share your thoughts about it?
It is pretty common pattern to have generic data access classes having create/update/delete/find methods concretely defined in an abstract super class, and then extend it for specific (JPA) entities with (possibly) more finders etc. in it.
It is really awkward to delegate these methods in every sub class.
We do have use cases where these kind of base classes with generic methods are used with different transaction managers.

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on in: data Issues in data modules (jdbc, orm, oxm, tx) in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task and removed type: task A general task labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process
Projects
None yet
Development

No branches or pull requests

2 participants