Skip to content

Commit

Permalink
Improve docs on transactionality of methods declared on repository in…
Browse files Browse the repository at this point in the history
…terfaces.

We're now more specific on what CRUD methods means in the context of transactional query methods. Also, we now mention default methods explicitly in the discussion of query methods.

Fixes #2868.
  • Loading branch information
odrotbohm committed Mar 19, 2023
1 parent 03b3516 commit edef7d7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/asciidoc/jpa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ include::query-by-example.adoc[leveloffset=+1]
[[transactions]]
== Transactionality

By default, CRUD methods on repository instances inherited from link:$$https://docs.spring.io/spring-data/data-jpa/docs/current/api/org/springframework/data/jpa/repository/support/SimpleJpaRepository.html$$[`SimpleJpaRepository`] are transactional.
By default, methods inherited from `CrudRepository` inherited the transactional configuration from from link:$$https://docs.spring.io/spring-data/data-jpa/docs/current/api/org/springframework/data/jpa/repository/support/SimpleJpaRepository.html$$[`SimpleJpaRepository`].
For read operations, the transaction configuration `readOnly` flag is set to `true`.
All others are configured with a plain `@Transactional` so that default transaction configuration applies.
Repository methods that are backed by transactional repository fragments inherit the transactional attributes from the actual fragment method.
Expand Down Expand Up @@ -1182,7 +1182,8 @@ Note that the call to `save` is not strictly necessary from a JPA point of view,
[[transactional-query-methods]]
=== Transactional query methods

To let your query methods be transactional, use `@Transactional` at the repository interface you define, as shown in the following example:
Declared query methods (including default methods) do not get any transaction configuration applied by default.
To run those methods transactionally, use `@Transactional` at the repository interface you define, as shown in the following example:

.Using @Transactional at query methods
====
Expand Down

0 comments on commit edef7d7

Please sign in to comment.