Note that isolation level and timeout settings will not get applied unless
an actual new transaction gets started. As only PROPAGATION_REQUIRED,
PROPAGATION_REQUIRES_NEW, and PROPAGATION_NESTED can cause
that, it usually doesn't make sense to specify those settings in other cases.
Furthermore, be aware that not all transaction managers will support those
advanced features and thus might throw corresponding exceptions when given
non-default values.
The read-only flag applies to any transaction context,
whether backed by an actual resource transaction or operating non-transactionally
at the resource level. In the latter case, the flag will only apply to managed
resources within the application, such as a Hibernate Session.
PlatformTransactionManager#getTransaction(TransactionDefinition), org.springframework.transaction.support.DefaultTransactionDefinition , org.springframework.transaction.interceptor.TransactionAttribute
| Modifier and Type | Field and Description |
|---|---|
| public static final int | ISOLATION_DEFAULT
Use the default isolation level of the underlying datastore. |
| public static final int | ISOLATION_READ_COMMITTED
Indicates that dirty reads are prevented; non-repeatable reads and phantom reads can occur. |
| public static final int | ISOLATION_READ_UNCOMMITTED
Indicates that dirty reads, non-repeatable reads, and phantom reads can occur. |
| public static final int | ISOLATION_REPEATABLE_READ
Indicates that dirty reads and non-repeatable reads are prevented; phantom reads can occur. |
| public static final int | ISOLATION_SERIALIZABLE
Indicates that dirty reads, non-repeatable reads, and phantom reads are prevented. |
| public static final int | PROPAGATION_MANDATORY
Support a current transaction; throw an exception if no current transaction exists. |
| public static final int | PROPAGATION_NESTED
Execute within a nested transaction if a current transaction exists,
behaving like |
| public static final int | PROPAGATION_NEVER
Do not support a current transaction; throw an exception if a current transaction exists. |
| public static final int | PROPAGATION_NOT_SUPPORTED
Do not support a current transaction; rather always execute non-transactionally. |
| public static final int | PROPAGATION_REQUIRED
Support a current transaction; create a new one if none exists. |
| public static final int | PROPAGATION_REQUIRES_NEW
Create a new transaction, suspending the current transaction if one exists. |
| public static final int | PROPAGATION_SUPPORTS
Support a current transaction; execute non-transactionally if none exists. |
| public static final int | TIMEOUT_DEFAULT
Use the default timeout of the underlying transaction system, or none if timeouts are not supported. |
| Modifier and Type | Method and Description |
|---|---|
| public default int | |
| public default String | Returns: the name of this transaction (null by default}Return the name of this transaction. |
| public default int | |
| public default int | |
| public default boolean | Returns: true if the transaction is to be optimized as read-only
(false by default)Return whether to optimize as a read-only transaction. |
| public static TransactionDefinition |
| ISOLATION_DEFAULT | back to summary |
|---|---|
| public static final int ISOLATION_DEFAULT Use the default isolation level of the underlying datastore. All other levels correspond to the JDBC isolation levels.
| |
| ISOLATION_READ_COMMITTED | back to summary |
|---|---|
| public static final int ISOLATION_READ_COMMITTED Indicates that dirty reads are prevented; non-repeatable reads and phantom reads can occur. This level only prohibits a transaction from reading a row with uncommitted changes in it. | |
| ISOLATION_READ_UNCOMMITTED | back to summary |
|---|---|
| public static final int ISOLATION_READ_UNCOMMITTED Indicates that dirty reads, non-repeatable reads, and phantom reads can occur. This level allows a row changed by one transaction to be read by another transaction before any changes in that row have been committed (a "dirty read"). If any of the changes are rolled back, the second transaction will have retrieved an invalid row. | |
| ISOLATION_REPEATABLE_READ | back to summary |
|---|---|
| public static final int ISOLATION_REPEATABLE_READ Indicates that dirty reads and non-repeatable reads are prevented; phantom reads can occur. This level prohibits a transaction from reading a row with uncommitted changes in it, and it also prohibits the situation where one transaction reads a row, a second transaction alters the row, and the first transaction re-reads the row, getting different values the second time (a "non-repeatable read"). | |
| ISOLATION_SERIALIZABLE | back to summary |
|---|---|
| public static final int ISOLATION_SERIALIZABLE Indicates that dirty reads, non-repeatable reads, and phantom reads are prevented. This level includes the prohibitions in | |
| PROPAGATION_MANDATORY | back to summary |
|---|---|
| public static final int PROPAGATION_MANDATORY Support a current transaction; throw an exception if no current transaction exists. Analogous to the EJB transaction attribute of the same name. Note that transaction synchronization within a | |
| PROPAGATION_NESTED | back to summary |
|---|---|
| public static final int PROPAGATION_NESTED Execute within a nested transaction if a current transaction exists,
behaving like Note Actual creation of a nested transaction will only work on
specific transaction managers. Out of the box, this only applies to the JDBC
| |
| PROPAGATION_NEVER | back to summary |
|---|---|
| public static final int PROPAGATION_NEVER Do not support a current transaction; throw an exception if a current transaction exists. Analogous to the EJB transaction attribute of the same name. Note that transaction synchronization is not available within a
| |
| PROPAGATION_NOT_SUPPORTED | back to summary |
|---|---|
| public static final int PROPAGATION_NOT_SUPPORTED Do not support a current transaction; rather always execute non-transactionally. Analogous to the EJB transaction attribute of the same name. Note Actual transaction suspension will not work out-of-the-box
on all transaction managers. This in particular applies to
Note that transaction synchronization is not available within a
| |
| PROPAGATION_REQUIRED | back to summary |
|---|---|
| public static final int PROPAGATION_REQUIRED Support a current transaction; create a new one if none exists. Analogous to the EJB transaction attribute of the same name. This is typically the default setting of a transaction definition and typically defines a transaction synchronization scope. | |
| PROPAGATION_REQUIRES_NEW | back to summary |
|---|---|
| public static final int PROPAGATION_REQUIRES_NEW Create a new transaction, suspending the current transaction if one exists. Analogous to the EJB transaction attribute of the same name. Note Actual transaction suspension will not work out-of-the-box
on all transaction managers. This in particular applies to
A | |
| PROPAGATION_SUPPORTS | back to summary |
|---|---|
| public static final int PROPAGATION_SUPPORTS Support a current transaction; execute non-transactionally if none exists. Analogous to the EJB transaction attribute of the same name. Note For transaction managers with transaction synchronization,
In general, use | |
| TIMEOUT_DEFAULT | back to summary |
|---|---|
| public static final int TIMEOUT_DEFAULT Use the default timeout of the underlying transaction system, or none if timeouts are not supported. | |
| getIsolationLevel | back to summary |
|---|---|
| public default int getIsolationLevel() Return the isolation level. Must return one of the Exclusively designed for use with The default is
| |
| getName | back to summary |
|---|---|
| public default String getName() Return the name of this transaction. Can be This will be used as the transaction name to be shown in a transaction monitor, if applicable. In case of Spring's declarative transactions, the exposed name will be
the
| |
| getPropagationBehavior | back to summary |
|---|---|
| public default int getPropagationBehavior() Return the propagation behavior. Must return one of the The default is
| |
| getTimeout | back to summary |
|---|---|
| public default int getTimeout() Return the transaction timeout. Must return a number of seconds, or Exclusively designed for use with Note that a transaction manager that does not support timeouts will throw
an exception when given any other timeout than The default is
| |
| isReadOnly | back to summary |
|---|---|
| public default boolean isReadOnly() Return whether to optimize as a read-only transaction. The read-only flag applies to any transaction context, whether backed
by an actual resource transaction ( This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction.
| |
| withDefaults | back to summary |
|---|---|
| public static TransactionDefinition withDefaults() Return an unmodifiable For customization purposes, use the modifiable
| |