In my code, I was persisting a row of data and had a catch block to throw a (custom) error when a constraint violation was thrown at the DB level. It was a bit messy how I had to get there but it worked.
catch (RollbackException ex){
if(ex.getCause() instanceof PersistenceException) {
PersistenceException pe = (PersistenceException) ex.getCause();
if (pe.getCause() instanceof ConstraintViolationException) {
ex.printStackTrace();
throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
}
}
}
Now for mysterious reasons, it seems the error getting thrown is no longer an instance of RollbackException so I had to just catch it at the PersistenceException level.
catch (PersistenceException ex) {
if (ex.getCause() instanceof ConstraintViolationException) {
ex.printStackTrace();
throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
}
}
What has me so perplexed is I haven't made any changes to the JPA Implementation Layer ( Hibernate 5.4.2.Final) or anything specific about the constraint I put on the table. The only thing I can think of is at some point we upgrade postgres from version 10 to version 11 but from an app standpoint that switch was invisible. Would that change the error getting thrown? I'm having trouble finding anything online to support the closest working theory.