I am fairly new to JPA and want to find best practices when handling persistence exceptions from JPA for things like say, unique constraint violations which can be
I'm doing something similar in my DB service layer to figure out whether the exception was caused by a conflicting constraint or general DB failure:
try {
....
} catch (final PersistenceException e) {
final Throwable cause = e.getCause();
if (cause instanceof MySQLIntegrityConstraintViolationException) {
throw new ConflictException(cause);
}
throw new ServiceException(e);
}