Refer to the exhibit.
Assume that the application is using Spring transaction management which uses Spring AOP internally.
Choose the statement that describes what is happening when the update1 method is called? (Choose the best answer.)
Refer to the exhibit.
Assume that the application is using Spring transaction management which uses Spring AOP internally.
Choose the statement that describes what is happening when the update1 method is called? (Choose the best answer.)
When the update1() method is called, it starts a transaction due to the @Transactional annotation with Propagation.REQUIRED. Within this transaction, the update2() method is called. Although update2() has a @Transactional annotation with Propagation.REQUIRES_NEW, it does not create a new transaction because the call to update2() is an internal method call within the same class. Spring AOP proxies only apply to external method calls, so the call to update2() does not go through the proxy. Therefore, only one transaction is initiated by update1().
Answer is D. Based on the lecture video from Vmware's training course (Spring framework essentials> Module 9 > Configure Transaction Propagation): The first update method will create a transaction and run in a proxy, and when the second update method is called, it will be executed within the same transaction in the same proxy.
Now you might be asking, why would it execute within the same transaction if the propagation is REQUIRES_NEW? Wouldn't it create a new transaction? Normally yes, however, In this case, the update2() method is being called in the same class as the first update(), making it an internal call. When the first update method was called the @Transactional annotation passed the method execution to the interceptor, which created a proxy for the transaction (Spring AOP). When the Internal call to the second update2() method was executed, it couldn't be intercepted by a new interceptor, therefore, it couldn't create its own transactional proxy, which means it cannot create a new transaction. If you don't understand this concept right away, don't worry. I had to review the video several times and I'm still trying to wrap my head around it.
Same here. Luckily the instructor in the video did mention this and illustrated this in his slides 3:42 minutes into the video. Took me a while to filter though all the stuff.
The option D is correct due to this article, where this case resolved - https://www.marcobehler.com/guides/spring-transaction-management-transactional-in-depth
A is correct
The answer should be A. There should be two transactions. The first one will be suspended when the second one is called and once the second transaction is done, the first one will become active again. Please refer to the Spring Docs on the topic of Transaction propagation: https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative/tx-propagation.html
UPDATE: I went though the VMWare Spring Framework Essentials lecture video where they used this exact example. The answer is indeed D. Feel to stupid for my original post. Apologies for the confusion.
I think is A correct answer Option B is incorrect because an exception is not thrown when using REQUIRES_NEW propagation. Option C is incorrect because REQUIRES_NEW will always create a new transaction even if an active transaction is present. Option D is also incorrect because the call to update2() does go through the proxy and the transactional behavior will be applied.