@ExceptionHandler({DataIntegrityViolationException.class}) public void constraintViolation(HttpServletResponse response, DataIntegrityViolationException ex) throws IOException { String message; Throwable cause = ex.getCause(); if (cause instanceof ConstraintViolationException) { ConstraintViolationException cEx = (ConstraintViolationException) cause; message = "Application already contain sent data (Constraint " + cEx.getConstraintName() + " violates)."; } else { message = ex.getMessage(); } response.sendError(CONFLICT.value(), message); }