Spring transaction propagation behavior in detail

The isolation level picture depends on the source

Transaction management at Snailclimb

Isolation level

Defines the extent to which a transaction is affected by other concurrent transactions

Problems caused by transaction concurrency

  • Dirty read: a transaction reads data modified by another transaction but not yet committed
  • Non-repeatable read: After a transaction has read data, the data has been modified by other transactions, and the first transaction to read data may be inconsistent.
  • Illusory: a transaction that reads some data and then reads more or less before committing, similar to the illusion (emphasis added or deleted)
  • Missing changes: Two transactions read data, one of which changes, the other also changes, the former changes lost

Five isolation levels (RU, RC, RR, Serializable)

  • ISOLATION_DEFAULT: use database default, oracle default RC, mysql default RR
  • ISOLATION_READ_UNCOMMITTED: Uncommitted data can be read without resolving the problem
  • ISOLATION_READ_COMMITTED: Committed data can be read, only resolvedDirty read
  • ISOLATION_REPEATABLE_READ: The result of reading a field data repeatedly is the sameDirty readUnrepeatable read, may still be illusory
  • ISOLATION_SERIALIZABLE: Serial no concurrency, solve all problems

Transaction propagation behavior

How does a transaction propagate when a method decorated by transaction propagation behavior is nested within another method

Seven kinds of transmission behavior

  • PROPAGATION_REQUIRED: If a transaction exists, it is added to form the same transaction, PROPAGATION_REQUIRED: If no transaction exists, it is opened. Internal transactions are independent of each other
  • 5, PROPAGATION_REQJIRES_NEW: New transactions are opened for both external and non-external transactions, independent of each other, and independent of external transactions
  • PROPAGATION_SUPPORTS: Non-transaction execution if there are no transactions around, and REQUIRED if there are
  • PROPAGATION_NOT_SUPPORTED: Non-transactionally executed, or suspends a transaction if one exists around it
  • PROPAGATION_MANDATORY: Peripheral transactions are used, and an exception is thrown if there are none
  • PROPAGATION_NEVER: Non-transactionally executed, throws an exception if a transaction exists around it
  • PROPAGATION_NESTED: When there are no external services, the services are independent of the internal services REQUIRED. If there are external transactions, the internal transaction is a sub-transaction. If the main transaction rolls back, all the sub-transactions are rolled back. The rollback of the sub-transaction does not affect other sub-transactions and the main transaction