i have a method in Service A
@Transactional
public void doSomething() {
for (int i = 0; i < 100; i++) {
anotherService.doThing();
}
}
And another method in Service B
@Transactional(propagation = REQUIRES_NEW, noRollbackFor = RuntimeException.class)
public void doThing() {
...
try {
repository.insertRandomValue();
} catch (Exception ignored) {
}
...
}
My problem is that when "repository.insertRandomValue()" throws ConstraintViolationException for example, then even tho it was caught in catch(), the thread ends with
org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only
I have tried setting the propagation to REQUIRES_NEW and tried to set up transaction manager and GlobalRollbackOnParticipationFailure to false.
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager manager = new JpaTransactionManager(entityManagerFactory);
manager.setGlobalRollbackOnParticipationFailure(false);
return manager;
}
I want it to simply ignore the failed insert attampts and continue working. Does anyone have an idea how to achieve that?