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: Class-level `@Transactional` doesn't demarcate transactions for public methods in parent class [SPR-17445] #21977

Closed
spring-issuemaster opened this Issue Oct 30, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Oct 30, 2018

Josh Long opened SPR-17445 and commented

i have a class that has a @Transactional on the class itself. It inherits from a base class. The base class implements an interface with methods on it and has a public methods in it. 

@Transactional 
@Service

class FooService extends BaseService \{ }

 

My expectation is that the public methods in BaseService should be demarcated in a transaction. If I do nothing but override the methods and then call the super implementation, things work as expected. 

 

the good Dr. dsyer investigated the issue further.

My code is https://github.com/reactive-spring-book/bootstrap/blob/master/src/main/java/rsb/bootstrap/enable/TransactionalCustomerService.java 

 

If you remove the 3 methods, findById, save, and findAll, they are still public methods in BaseCustomerService. I have a test that tests that i can write data to the DB and see it roll back. the test fails if i have removed those methods. it succeeds when i add them.


Affects: 5.1.2

Referenced from: commits ea3250c, 561511f, f002ebd

Backported to: 5.0.11, 4.3.21

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 30, 2018

Dave Syer commented

It looks to me like the logic in AbstractFallbackTransactionAttributeSource.computeTransactionAttribute() simply never took this scenario into account: someone annotates TransactionalCustomerService as @Transactional but all the methods are declared in a base class. The Method that is analyzed doesn't have the @Transactional annotation and neither does its declaring class, but the bean class does.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 30, 2018

Juergen Hoeller commented

This is by design: A class-level transactional demarcation only applies to the methods as per its level in the inheritance hierarchy. Redeclaring methods at that level is exactly what it takes to include them in such a class-level transactional demarcation, or of course locally annotating the redeclared methods themselves. This allows for fine-tuning the scope of the transactional demarcation through putting methods at the appropriate place in the inheritance hierarchy.

In any case, we need to document this properly.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 5, 2018

Juergen Hoeller commented

I've added corresponding notes to the annotation javadoc as well as the reference docs, also taking the opportunity to mention @EnableTransactionManagement earlier in the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.