In a 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 exactly the transaction created for m2()
is committed? once m2()
invocation ends, or once m1()
invocation ends?
When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit? answers it for EJB, but it doesn't seem to be the same behavior for JPA.
I debugged it and I can only see the effect of m2()
on DB after m1()
ends, but that seems odd to me, am I missing something here?
UPDATE:
I was passing the entity I retrieved in m1()
to m2()
and updating it from there.
So, actually merging the entity in m2()
solves this and Mik378 answer is correct.