code: private static void validateOrderBy(Attribute attr, Sort orderBy) {
      if (orderBy != null) {
        EntityType refEntity = attr.getRefEntity();
        if (refEntity != null) {
          for (Sort.Order orderClause : orderBy) {
            String refAttrName = orderClause.getAttr();
            if (refEntity.getAttribute(refAttrName) == null) {
              throw new MolgenisDataException(
                  format(
                      "Unknown entity [%s] attribute [%s] referred to by entity [%s] attribute [%s] sortBy [%s]",
                      refEntity.getId(),
                      refAttrName,
                      attr.getEntityType().getId(),
                      attr.getName(),
                      orderBy.toSortString()));
            }
          }
        }
      }
    }
docs: Validate whether the attribute names defined by the orderBy attribute point to existing
  attributes in the referenced entity.
  
  @param attr attribute
  @param orderBy orderBy of attribute
  @throws MolgenisDataException if orderBy contains attribute names that do not exist in the
  referenced entity.