@ExceptionHandler(value={JpaSystemException.class,PersistenceException.class}) @ResponseBody public ErrorInformation handlePersistenceException(Exception exception,HttpServletResponse response){
  Throwable throwable=getRootCause(exception);
  if (isDataTruncationException(throwable)) {
    return getErrorInformationAndSetStatus(HttpStatus.BAD_REQUEST,throwable,response);
  }
 else   if (isCausedByConstraintViolationException(exception)) {
    return getErrorInformationAndSetStatus(HttpStatus.BAD_REQUEST,new Exception("A constraint has been violated. Reason: " + throwable.getMessage()),response);
  }
 else {
    logError("A persistence error occurred.",exception);
    return getErrorInformationAndSetStatus(HttpStatus.INTERNAL_SERVER_ERROR,throwable == null ? new Exception("General Error") : throwable,response);
  }
}

@ ExceptionHandler ( value = { JpaSystemException . class , PersistenceException . class } ) @ ResponseBody public ErrorInformation handlePersistenceException ( Exception exception , HttpServletResponse response ) { Throwable throwable = getRootCause ( exception ) ; if ( isDataTruncationException ( throwable ) ) { return getErrorInformationAndSetStatus ( HttpStatus . BAD_REQUEST , throwable , response ) ; } else if ( isCausedByConstraintViolationException ( exception ) ) { return getErrorInformationAndSetStatus ( HttpStatus . BAD_REQUEST , new Exception ( "A constraint has been violated. Reason: " + throwable . getMessage ( ) ) , response ) ; } else { logError ( "A persistence error occurred." , exception ) ; return getErrorInformationAndSetStatus ( HttpStatus . INTERNAL_SERVER_ERROR , throwable == null ? new Exception ( "General Error" ) : throwable , response ) ; } }
handle persistence exceptions thrown by handlers . note that this method properly handles a null response being passed in .
