Skip to content

Clarify transaction boundary recommendation #3842

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
seungcheol-kwon opened this issue Apr 16, 2025 · 2 comments
Closed

Clarify transaction boundary recommendation #3842

seungcheol-kwon opened this issue Apr 16, 2025 · 2 comments
Assignees
Labels
type: documentation A documentation update

Comments

@seungcheol-kwon
Copy link

Hi Spring Data JPA team,

While reading the official documentation on transaction management
(https://github.com/spring-projects/spring-data-jpa/blob/3.4.4/src/main/antora/modules/ROOT/pages/jpa/transactions.adoc),
I noticed that it might give the impression that @Transactional should be placed on the repository layer to define transaction boundaries.

However, in most real-world applications, transaction boundaries are typically defined at the service layer.
This is because the service layer represents the unit of business logic that should execute atomically,
and transaction control is better handled in the service layer for consistency and clarity.

So I’d like to clarify the actual intent of the documentation:
Is it encouraging developers to define @Transactional on the repository layer, or was that example simply meant to demonstrate how to provide default read-only settings?

Currently, it can be misinterpreted as a recommendation to control transactions at the repository level.
If that’s not the intended message, I believe it would be helpful to revise or clarify the documentation to prevent confusion.

Thanks for your great work on the project, and I look forward to your guidance!

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

mp911de commented Apr 16, 2025

Declaring transaction (unit of work) bounds is a wide field that can easily fill a hour-long discussion. We've decided to keep our docs focused on the repository aspect as that is the the latest point where transaction management should happen.

We generally recommend that you start your transaction much earlier and that repositories participate on your transaction. If you want that only the repository participates in a transaction but not your surrounding calls, then annotating the repository (or fragment) methods is the way to go.

Let me know whether this helps and whether the details stated above help to avoid misinterpretations so we can refine our docs.

@mp911de mp911de added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 16, 2025
@mp911de mp911de self-assigned this Apr 16, 2025
@mp911de mp911de added status: waiting-for-triage An issue we've not yet triaged status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 16, 2025
@seungcheol-kwon
Copy link
Author

Thanks for the helpful explanation!

Based on your feedback, I’ve opened a PR to make the documentation a bit clearer:
#3843

If the proposed change doesn’t quite match your intent, I’m more than happy to revise or discuss it further.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 16, 2025
@mp911de mp911de changed the title Question: Does the JPA Transaction Docs Recommend Using @Transactional on Repositories? Clarify transaction boundary recommendation Apr 17, 2025
@mp911de mp911de added this to the 3.3.11 (2024.0.11) milestone Apr 17, 2025
mp911de pushed a commit that referenced this issue Apr 17, 2025
mp911de added a commit that referenced this issue Apr 17, 2025
Tweak wording.

See #3842
Original pull request: #3843
mp911de added a commit that referenced this issue Apr 17, 2025
Tweak wording.

See #3842
Original pull request: #3843
mp911de pushed a commit that referenced this issue Apr 17, 2025
mp911de added a commit that referenced this issue Apr 17, 2025
Tweak wording.

See #3842
Original pull request: #3843
@mp911de mp911de removed the status: feedback-provided Feedback has been provided label Apr 17, 2025
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 a pull request may close this issue.

3 participants