Skip to content

Improve wording on transactional methods inherited from SimpleJpaRepository and repository fragments #2207

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

Conversation

vananiev
Copy link

@vananiev vananiev commented Apr 26, 2021

Transactionality documentation sectional may mislead about apply @Transactional for custom repository, which extends JpaRepository (proof).

Spring JPA JavaDoc may be clarified by this PR.

Tests:
I test

public interface SecurityRepository extends JpaRepository<SecurityEntity, String> {
    Collection<SecurityEntity> findByIdStartingWith(String with);
}

method call with property

logging.level.org.springframework.transaction.interceptor = TRACE

When no @Transactional on class or method, transaction for custom method is not created

o.s.t.i.TransactionInterceptor           : No need to create transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findByIdStartingWith]: This method is not transactional.

With annotation on class or method level transaction is created

o.s.t.i.TransactionInterceptor           : Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findByIdStartingWith]
o.s.t.i.TransactionInterceptor           : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findByIdStartingWith]

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 26, 2021
@mp911de
Copy link
Member

mp911de commented Apr 27, 2021

Actually, methods on JpaRepository and JpaSpecificationExecutor are transactional as SimpleJpaRepository is marked as @Transactional(readOnly = true).

@vananiev
Copy link
Author

Yes. You give measlead answer as documentation. That's a problem. Does your answer follow that SecurityRepository .findByIdStartingWith() is tarnsactional? Test shows that no.

@mp911de
Copy link
Member

mp911de commented Apr 27, 2021

Does your answer follow that SecurityRepository .findByIdStartingWith() is tarnsactional? Test shows that no.

findByIdStartingWith(…) is not declared on JpaRepository or JpaSpecificationExecutor, it is declared on SecurityRepository and likely it isn't annotated with @Transactional.

Therefore your observation is correct. Note that transactional attributes defined on SimpleJpaRepository (which is the primary implementation of JpaRepository and JpaSpecificationExecutor) do not affect query methods you declare on your repository unless you override a method of JpaRepository or JpaSpecificationExecutor.

@vananiev
Copy link
Author

vananiev commented Apr 27, 2021

Yes, but doc says about [all] CRUD methods of repository

By default, CRUD methods on repository instances are transactional

This part may be clarified by this PR.

@mp911de
Copy link
Member

mp911de commented Apr 27, 2021

This part may be clarified by this PR.

This PR addresses only a subset, so my intent is rather to mention both interfaces to document the exact behavior to expect.

@vananiev
Copy link
Author

Ok, will you make it yourself or my help required?

@mp911de
Copy link
Member

mp911de commented Apr 27, 2021

I can take it if you don't mind.

@mp911de mp911de self-assigned this Apr 27, 2021
@vananiev
Copy link
Author

vananiev commented Apr 27, 2021

Ok, but I want to to check if explanation will be clean.

@mp911de mp911de changed the title Clarifying Transactionality doc Improve wording on transactional methods inherited from SimpleJpaRepository and repository fragments May 3, 2021
@mp911de mp911de closed this in f33a353 May 3, 2021
mp911de added a commit that referenced this pull request May 3, 2021
mp911de added a commit that referenced this pull request May 3, 2021
@mp911de mp911de added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels May 3, 2021
@mp911de mp911de added this to the 2.4.9 (2020.0.9) milestone May 3, 2021
mp911de added a commit that referenced this pull request May 3, 2021
mp911de added a commit that referenced this pull request May 3, 2021
mp911de added a commit that referenced this pull request May 3, 2021
@vananiev vananiev deleted the task-update-transactional-doc branch May 16, 2021 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants