3

I have been reading about @EnableTransactionManagement and then @Transactional annotations which ensures that say if a transaction involves 3 DAO operations and the 3rd fails then the first 2 also rolls back. Also, it helps when concurrent threads are accessing the same method/class. However, I could not understand what exactly a Transaction is?

I have assumed from the numerous answers on StackOverflow and other places that it is an operation when data is manipulated in the Db from the Spring Boot application. Am I correct? I could not find any question on STF that asks this question.

Nitin Nanda
  • 805
  • 2
  • 11
  • 27
  • 1
    https://en.wikipedia.org/wiki/Database_transaction – R.G Feb 14 '20 at 15:31
  • Long story short, a transaction is all or nothing... when you do 10 updates under a transaction, either they all go through or they all get rolled back – RobOhRob Feb 14 '20 at 15:42

1 Answers1

2

Yes you are correct. See this answer for a good explanation What is a database transaction?.

From the Spring point of view, the @Transactional annotation will create an AOP point cut around your method. What this essentially does, is makes sure that any DB related queries that are executed within your method, are wrapped into a Transaction and executed as a single unit of work.

Brendon Randall
  • 1,436
  • 3
  • 14
  • 25