I am trying to insert and update on a table, by reading messages from active mq triggered via separate threads each time. At times insert query fails because of ConstraintVoilationException. I want to do a retry as the code will consider the retry attempt as an update and ConstraintVoilationException won't appear.
However, RetryPolicy is not working on this exception. How can I customize it?
Failsafe artifact version: net.jodah (2.3.3)
Here is the code sample, where 'T' is the className of my entity.
@Transactional
processTxn(T t){
RetryPolicy<T> rp = RetryPolicy<T>.handle(ConstraintVoilationException.class).withMaxRetries(3);
Failsafe.with(rp).run(() -> insertOrUpdateMethod(t));
}
@Transactional
insertOrUpdateMethod (T t){
//Fetch instance of t from DB, if it exists - fire update on a few columns
//else insert a new row
}
I have also tried this code with DataIntegrityVoilationException and SQLIntegrityConstraintVoilationException but the code doesn't retry after failure.