@@ -195,16 +195,16 @@ execution.
195
195
196
196
The `TransactionDefinition` interface specifies:
197
197
198
- * __Isolation__: The degree to which this transaction is isolated from the work of other
199
- transactions. For example, can this transaction see uncommitted writes from other
200
- transactions?
201
198
* __Propagation__: Typically, all code executed within a transaction scope will run in
202
199
that transaction. However, you have the option of specifying the behavior in the event
203
200
that a transactional method is executed when a transaction context already exists. For
204
201
example, code can continue running in the existing transaction (the common case); or
205
202
the existing transaction can be suspended and a new transaction created. __Spring
206
203
offers all of the transaction propagation options familiar from EJB CMT__. To read
207
204
about the semantics of transaction propagation in Spring, see <<tx-propagation>>.
205
+ * __Isolation__: The degree to which this transaction is isolated from the work of other
206
+ transactions. For example, can this transaction see uncommitted writes from other
207
+ transactions?
208
208
* __Timeout__: How long this transaction runs before timing out and being rolled back
209
209
automatically by the underlying transaction infrastructure.
210
210
* __Read-only status__: A read-only transaction can be used when your code reads but
@@ -1021,17 +1021,17 @@ that are nested within `<tx:advice/>` and `<tx:attributes/>` tags are summarized
1021
1021
| `isolation`
1022
1022
| No
1023
1023
| DEFAULT
1024
- | Transaction isolation level.
1024
+ | Transaction isolation level. Only applicable to propagation REQUIRED or REQUIRES_NEW.
1025
1025
1026
1026
| `timeout`
1027
1027
| No
1028
1028
| -1
1029
- | Transaction timeout value (in seconds).
1029
+ | Transaction timeout ( seconds). Only applicable to propagation REQUIRED or REQUIRES_NEW .
1030
1030
1031
1031
| `read-only`
1032
1032
| No
1033
1033
| false
1034
- | Is this transaction read-only?
1034
+ | Read/write vs. read-only transaction. Only applicable to REQUIRED or REQUIRES_NEW.
1035
1035
1036
1036
| `rollback-for`
1037
1037
| No
@@ -1155,7 +1155,6 @@ transactional behavior.
1155
1155
1156
1156
[TIP]
1157
1157
====
1158
-
1159
1158
Spring recommends that you only annotate concrete classes (and methods of concrete
1160
1159
classes) with the `@Transactional` annotation, as opposed to annotating interfaces. You
1161
1160
certainly can place the `@Transactional` annotation on an interface (or an interface
@@ -1301,23 +1300,23 @@ annotation are summarized in the following table:
1301
1300
1302
1301
| <<tx-multiple-tx-mgrs-with-attransactional,value>>
1303
1302
| String
1304
- | Optional qualifier specifying the transaction manager to be used.
1303
+ | Optional qualifier specifying the transaction manager to be used.
1305
1304
1306
1305
| <<tx-propagation,propagation>>
1307
1306
| enum: `Propagation`
1308
1307
| Optional propagation setting.
1309
1308
1310
1309
| `isolation`
1311
1310
| enum: `Isolation`
1312
- | Optional isolation level.
1313
-
1314
- | `readOnly`
1315
- | boolean
1316
- | Read/write vs. read-only transaction
1311
+ | Optional isolation level. Only applicable to propagation REQUIRED or REQUIRES_NEW.
1317
1312
1318
1313
| `timeout`
1319
1314
| int (in seconds granularity)
1320
- | Transaction timeout.
1315
+ | Optional transaction timeout. Only applicable to propagation REQUIRED or REQUIRES_NEW.
1316
+
1317
+ | `readOnly`
1318
+ | boolean
1319
+ | Read/write vs. read-only transaction. Only applicable to REQUIRED or REQUIRES_NEW.
1321
1320
1322
1321
| `rollbackFor`
1323
1322
| Array of `Class` objects, which must be derived from `Throwable.`
@@ -1451,11 +1450,28 @@ image::images/tx_prop_required.png[]
1451
1450
1452
1451
PROPAGATION_REQUIRED
1453
1452
1453
+ `PROPAGATION_REQUIRED` enforces a physical transaction: either locally for the current
1454
+ scope if no transaction exists yet, or participating in an existing 'outer' transaction
1455
+ defined for a larger scope. This is a fine default in common call stack arrangements
1456
+ within the same thread, e.g. a service facade delegating to several repository methods
1457
+ where all the underlying resources have to participate in the service-level transaction.
1458
+
1459
+ [NOTE]
1460
+ ====
1461
+ By default, a participating transaction will join the characteristics of the outer scope,
1462
+ silently ignoring the local isolation level, timeout value or read-only flag (if any).
1463
+ Consider switching the "validateExistingTransactions" flag to "true" on your transaction
1464
+ manager if you'd like isolation level declarations to get rejected when participating in
1465
+ an existing transaction with a different isolation level. This non-lenient mode will also
1466
+ reject read-only mismatches, i.e. an inner read-write transaction trying to participate
1467
+ in a read-only outer scope.
1468
+ ====
1469
+
1454
1470
When the propagation setting is `PROPAGATION_REQUIRED`, a __logical__ transaction scope
1455
1471
is created for each method upon which the setting is applied. Each such logical
1456
1472
transaction scope can determine rollback-only status individually, with an outer
1457
- transaction scope being logically independent from the inner transaction scope. Of
1458
- course, in case of standard `PROPAGATION_REQUIRED` behavior, all these scopes will be
1473
+ transaction scope being logically independent from the inner transaction scope.
1474
+ Of course, in case of standard `PROPAGATION_REQUIRED` behavior, all these scopes will be
1459
1475
mapped to the same physical transaction. So a rollback-only marker set in the inner
1460
1476
transaction scope does affect the outer transaction's chance to actually commit (as you
1461
1477
would expect it to).
@@ -1477,11 +1493,14 @@ image::images/tx_prop_requires_new.png[]
1477
1493
1478
1494
PROPAGATION_REQUIRES_NEW
1479
1495
1480
- `PROPAGATION_REQUIRES_NEW`, in contrast to `PROPAGATION_REQUIRED`, uses a __completely__
1481
- independent transaction for each affected transaction scope. In that case, the
1482
- underlying physical transactions are different and hence can commit or roll back
1496
+ `PROPAGATION_REQUIRES_NEW`, in contrast to `PROPAGATION_REQUIRED`, always uses an
1497
+ __independent__ physical transaction for each affected transaction scope, never
1498
+ participating in an existing transaction for an outer scope. In such an arrangement,
1499
+ the underlying resource transactions are different and hence can commit or roll back
1483
1500
independently, with an outer transaction not affected by an inner transaction's rollback
1484
- status.
1501
+ status, and with an inner transaction's locks released immediately after its completion.
1502
+ Such an independent inner transaction may also declare its own isolation level, timeout
1503
+ and read-only settings, never inheriting an outer transaction's characteristics.
1485
1504
1486
1505
[[tx-propagation-nested]]
1487
1506
===== Nested
0 commit comments