I am having trouble with Spring Transactions. I need my catch block to persist some state on a forked/autonomous transaction then throw an exception to rollback whatever there was done on the primary transaction.
@Transactional(
propagation = Propagation.REQUIRED,
isolation = Isolation.READ_COMMITTED,
rollbackFor = {Exception.class})
public void createApplication() {
try {
saveState(0);
} catch(Exception e) {
saveState(1);
throw e;
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveState(Integet stateId) {
...
}
The issue with this setup is that everything gets rollbacked (as mentioned in How to partially rollback data in spring boot, errors to be persited). Is there a way to fork transactions in Spring or this way is fundamentally incorrect?
I've also tried pairing Propagation.REQUIRED with Propagation.NESTED without avail.