Monday, June 13, 2022

Spring Transaction Management

 

  • Transaction Propagation : Propagation defines our business logic's transaction boundary. Spring manages to start and pause a transaction according to our propagation setting. (in other words  : Defines how transactions relate to each other)
    • REQUIRED : Code will always run in a transaction. Creates a new transaction or reuses one if available.
    • REQUIRED_NEW : Code will always run in a new transaction. Suspends the current transaction if one exists.
    • SUPPORTS
    • MANDATORY
    • NEVER
    • NOT_SUPPORTED
    • NESTED

  • Transaction  Isolation :  solation is one of the common ACID properties: Atomicity, Consistency, Isolation, and Durability. Isolation describes how changes applied by concurrent transactions are visible to each other. (in other words :  Defines the data contract between transactions)
    Isolation Levels
    • DEFAULT 
    • READ_UNCOMMITTED : Allows dirty reads
    • READ_COMMITTED :  Does not allow dirty reads
    • REPEATABLE_READ : If a row is read twice in the same transaction, the result will always be the same 
    • SERIALIZABLE : Performs all transactions in a sequence
Each isolation level prevents zero or more concurrency side effects on a transaction:
  • Dirty read: read the uncommitted change of a concurrent transaction
  • Nonrepeatable read: get different value on re-read of a row if a concurrent transaction updates the same row and commits
  • Phantom read: get different rows after re-execution of a range query if another transaction adds or removes some rows in the range and commits

  • References

    Baeldung : link 

    Stackoverflow : link

    Transactions with Spring and JPA : link


    No comments:

    Post a Comment

    Thank you for your comment!