When transaction JPA REQUIRES_NEW is executed

In the spring container with the code below:

public class A { @Transactional public void m1() { ... b.m2(); // call in a new transaction ... } } public class B { @Transactional(propagation = Propagation.REQUIRES_NEW) public void m2() { ... } } 

when the transaction created for m2() ? when does the call to m2() end or call m1() ends?

When does @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) commit? answers it for EJB, but it doesn't seem to be like JPA behavior.

I debugged it, and I can see the effect of m2() on the DB after the end of m1() , but it seems strange to me, am I missing something here?

UPDATE:

I passed the object that I got in m1() to m2() and updated it from there. Thus, actually combining the object in m2() allows this and the correct answer of Mik378 .

+8
java spring java-ee hibernate jpa
source share
1 answer

From here :

Whether you use Spring Framework or EJB, use the REQUIRES_NEW transaction attribute can have negative results and lead to corrupted and inconsistent data.
The transaction REQUIRES_NEW attribute always starts a new transaction when the method starts, whether or not an existing transaction exists.

REQUIRES_NEW starts a new transaction, even if an existing transaction exists in context.

So the short answer is: once m2() terminates the call

+6
source share

All Articles