Skip to content

@Transactional on package-private/protected methods for class-based proxies #31057

Closed
@lukozog

Description

@lukozog

Hello, according to the documentation, to allow package-private or protected methods to benefit from @Transactional we have to register custom transactionAttributeSource. Previous statement based on Method visibility and @Transactional in https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/annotations.html

I found that for class-based proxies I can add @Transational over package-private or protected methods without any additional action or registering specific @Bean mentioned in the documentation. Observation while using Spring Framework version 6.0.8. I assume that it may work by default from version 6.0 M1 according to #25582

The issue is created to encourage change in documentation. Currently, whatever article we may find about @Transactional, or a tool like SonarLint, each says it's necessary to have a public method to use it. It seems to me that most of them are no longer current 😸 If we have in documentation something more precise, like mentioning that for class-based proxies it's just ok to use @Transactional above package-private or protected method, but for interface-based not, it would be much more clear to understand and use. It would allow to increase the encapsulation in the projects.

Thanks.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions