Does CDI @Transactional(Transactional.TxType.REQUIRES_NEW) works when is called inside the same bean:
@Transactional
public void method1() {
for(...) {
method2();
}
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void method2() {
...
}
I suppose it doesn't works because local calls can't be intercepted by the proxy. In that case what is the recommeded usage pattern if I want to manage each call of method2 in a new transaction. The obvious one is to create another bean, but it's something I don't like.
try
/catch
in yourmethod1
What happens if one of themethod2
transactions fails? Is the transaction surroundingmethod1
really still valid? Usually transactions give you an all-or-nothing semantics, and with your above code snippet I struggle to see the benefit of a nested transaction. FWIW, by the SRP you most probably still want to movemethod2
to another bean, in particular if its value/use-case even justifies a new transaction. – Default