EP-12a Spring Boot Transaction Management Example

Опубликовано: 01 Июнь 2025
на канале: gk-care
530
18

Spring Boot Transaction Management Example

Maintaining consistency across the data as per ACID properties is called transaction management.
1. Atomicity - Every DML statement is all unique transaction.
2. Consistency - Data should be accurate in case of failure/success.
3. Isolation - It will always get the data from the main block
4. Durability - Data should be the same and available at any point in time.
Scenario 1:
Test Case: Placing an order in Amazon
1) Customer Login = login = Vijay at timestamp = DML1
2) Add to Product = inventory Update = DML2…….DML10
3) Discount = order = Instant Discount = DML11
4) Payment = Payment t = failed
? How will roll back our data?
Is developer do it or framework will do it?

try{
update product set qty=qty-1 where productname=’mobile’
update product set qty=qty-1 where productname=’LCD’
}catch(Exception e){
update product set qty=qty+1 where productname=’mobile’
update product set qty=qty+1 where productname=’LCD’
}
How transaction will work in the background?
Database
• Cache memory
• Connection Memory
• Transaction Memory
• Session Memory
Transaction Memory
Begin Transaction
 Temp memory block will be created in transaction memory. All the DML will stored in temp memory
Commit
If all the cases are completed. Developer do commit then all DML change will be moved to the permanent memory block
Rollback
If some process fails during the transaction then rollback will triggered and all the changes in the temp memory block will be deleted

What is our Java programmer's Responsibility?
1) Need to tell my database, please start a transaction block
2) I need to make sure that all the DML should be triggered from this block only
3) Commit/Rollback: I need to tell the database
All the transaction block statements will be saved to the database's temporary memory, not on the application server like Tomcat
Let’s play what happens if we use Transactions

Notes : https://docs.google.com/document/d/1R...
....
Spring Boot – Transaction Management Using @Transactional Annotation,
Transaction Management,
Transactions with Spring and JPA,
Spring Transaction management: @Transactional,
Transactional management in Spring boot,
Spring Boot Declarative Transaction management Example,
Spring Data JPA Transaction management,
Spring @Transactional-What happens in background?,
The @Transactional annotation in Spring Boot,
managing Transactions with Spring and Spring Data JPA,
Spring boot jpa,
Spring BOOT Hibernate,
Postman,
Spring Boot JPA Mysql,