code: MolgenisValidationException translateForeignKeyViolation(PSQLException pSqlException) {
      ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
      String tableName = serverErrorMessage.getTable();
      String detailMessage = serverErrorMessage.getDetail();
      Matcher m = Pattern.compile("\\((.*?)\\)").matcher(detailMessage);
      if (!m.find()) {
        LOG.error(ERROR_TRANSLATING_POSTGRES_EXC_MSG, pSqlException);
        throw new RuntimeException(ERROR_TRANSLATING_EXCEPTION_MSG, pSqlException);
      }
      String colName = m.group(1);
      if (!m.find()) {
        LOG.error(ERROR_TRANSLATING_POSTGRES_EXC_MSG, pSqlException);
        throw new RuntimeException(ERROR_TRANSLATING_EXCEPTION_MSG, pSqlException);
      }
      String value = m.group(1);
  
      String constraintViolationMessageTemplate;
      String attrName;
      if (detailMessage.contains("still referenced from")) {
        // ERROR: update or delete on table "x" violates foreign key constraint "y" on table "z"
        // Detail: Key (k)=(v) is still referenced from table "x".
        constraintViolationMessageTemplate =
            "Value '%s' for attribute '%s' is referenced by entity '%s'.";
        String refTableName = getRefTableFromForeignKeyPsqlException(pSqlException);
        attrName = tryGetAttributeName(refTableName, colName).orElse(TOKEN_UNKNOWN);
      } else {
        // ERROR: insert or update on table "x" violates foreign key constraint "y"
        // Detail: Key (k)=(v) is not present in table "z".
        constraintViolationMessageTemplate =
            "Unknown xref value '%s' for attribute '%s' of entity '%s'.";
        attrName = tryGetAttributeName(tableName, colName).orElse(TOKEN_UNKNOWN);
      }
      ConstraintViolation constraintViolation =
          new ConstraintViolation(
              format(
                  constraintViolationMessageTemplate,
                  value,
                  attrName,
                  tryGetEntityTypeName(tableName).orElse(TOKEN_UNKNOWN)),
              null);
      return new MolgenisValidationException(singleton(constraintViolation));
    }
docs: Package private for testability
  
  @param pSqlException PostgreSQL exception
  @return translated validation exception