You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/jdbc.adoc
+6-2
Original file line number
Diff line number
Diff line change
@@ -920,7 +920,7 @@ Thus, if you want to inspect what SQL statements are run, activate logging for S
920
920
[[jdbc.transactions]]
921
921
== Transactionality
922
922
923
-
CRUD methods on repository instances are transactional by default.
923
+
The methods of `CrudRepository` instances are transactional by default.
924
924
For reading operations, the transaction configuration `readOnly` flag is set to `true`.
925
925
All others are configured with a plain `@Transactional` annotation so that default transaction configuration applies.
926
926
For details, see the Javadoc of link:{javadoc-base}org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.html[`SimpleJdbcRepository`].
@@ -1008,7 +1008,11 @@ Typically, you want the `readOnly` flag to be set to true, because most of the q
1008
1008
In contrast to that, `deleteInactiveUsers()` uses the `@Modifying` annotation and overrides the transaction configuration.
1009
1009
Thus, the method is with the `readOnly` flag set to `false`.
1010
1010
1011
-
NOTE: It is definitely reasonable to use transactions for read-only queries, and we can mark them as such by setting the `readOnly` flag.
1011
+
NOTE: It is highly recommended to make query methods transactional. These methods might execute more then one query in order to populate an entity.
1012
+
Without a common transaction Spring Data JDBC executes the queries in different connections.
1013
+
This may put excessive strain on the connection pool and might even lead to dead locks when multiple methods request a fresh connection while holding on to one.
1014
+
1015
+
NOTE: It is definitely reasonable to mark read-only queries as such by setting the `readOnly` flag.
1012
1016
This does not, however, act as a check that you do not trigger a manipulating query (although some databases reject `INSERT` and `UPDATE` statements inside a read-only transaction).
1013
1017
Instead, the `readOnly` flag is propagated as a hint to the underlying JDBC driver for performance optimizations.
0 commit comments