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.)
A.
There are 2 transactions because REQUIRES_NEW always runs in a new transaction.
B.
An exception is thrown as another transaction cannot be started within an existing transaction.
C.
There is only one transaction because REQUIRES_NEW will use an active transaction if one already exists.
D.
There is only one transaction initiated by update1() because the call to update2() does not go through the proxy.
This is a poor set of avaiable answers:
update() (there is no update1() method) will create a new transaction when executed, however update2() is REQUIRES_NEW which will suspend that transaction and create a new one,
until it has completed, and then return to the suspended transaction begun by update(), thus:
A is the most correct as there wuill be 2 transactions (even though one is suspended)
B this is false, new transactions can be started within existing ones
C is incorrect as it never uses an existing transaction (it suspends it)
D is incorrect because update 2 does begin a new transaction and is within a proxy
Therefore A is the most accurate in this context
However a closer look at the call stack of the transactions, update2() is called within the scope (and thus the proxy) of update() and therefore, despite REQUIRES_NEW starting a new transaction and suspending the initial one, it is none the less in the same Proxy created by update(), and in this context D is most accurate!
n Spring, transaction management relies on Spring AOP (Aspect-Oriented Programming), which means transactions are managed through proxies. For a new transaction (like one specified with REQUIRES_NEW) to be started within an existing transaction, the method must be called through a Spring proxy.
In the code provided, update1 calls update2 directly. This means the call does not go through the Spring proxy, and hence, the REQUIRES_NEW propagation on update2 is not recognized. As a result, there is only one transaction, which is the one initiated by update1.
If update2 were to be called in a way that went through the proxy, such as through another Spring-managed bean, a new transaction would indeed be started because of the REQUIRES_NEW propagation. However, the direct call prevents this from happening, leading to only one transaction.
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 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.
The option D is correct due to this article, where this case resolved -
https://www.marcobehler.com/guides/spring-transaction-management-transactional-in-depth
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.
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
stefumies
1 month agostefumies
1 month agoEvoila_TrainingMaterial
4 months ago2211094
4 months, 3 weeks agoAncient1
1 year, 3 months agoAncient1
1 year, 3 months agoAzuni
1 year, 3 months agoAzuni
1 year, 3 months agoAzuni
1 year, 3 months agoVerixas
1 year, 7 months agorhuanca
1 year, 8 months ago