public void addRefEntityId(String name, Object idValue) {
   HugeSet<Object> refEntityIds = refEntitiesIds.get(name);
   // only add entity id if this validation run requires entity
   if (refEntityIds != null) {
     refEntityIds.add(idValue);
   }
 }
  private void initReferenceValidation(ValidationResource validationResource) {
    // get reference attrs
    List<AttributeMetaData> refAttrs =
        StreamSupport.stream(getEntityMetaData().getAtomicAttributes().spliterator(), false)
            .filter(
                attr ->
                    (attr.getDataType() instanceof XrefField
                            || attr.getDataType() instanceof MrefField)
                        && attr.getExpression() == null)
            .collect(Collectors.toList());

    // get referenced entity ids
    if (!refAttrs.isEmpty()) {
      Map<String, HugeSet<Object>> refEntitiesIds = new HashMap<>();
      refAttrs.forEach(
          refAttr -> {
            EntityMetaData refEntityMeta = refAttr.getRefEntity();
            String refEntityName = refEntityMeta.getName();
            HugeSet<Object> refEntityIds = refEntitiesIds.get(refEntityName);
            if (refEntityIds == null) {
              refEntityIds = new HugeSet<>();
              refEntitiesIds.put(refEntityName, refEntityIds);

              Query q =
                  new QueryImpl()
                      .fetch(new Fetch().field(refEntityMeta.getIdAttribute().getName()));
              for (Iterator<Entity> it = dataService.findAll(refEntityName, q).iterator();
                  it.hasNext(); ) {
                refEntityIds.add(it.next().getIdValue());
              }
            }
          });

      validationResource.setRefEntitiesIds(refEntitiesIds);
    }

    validationResource.setRefAttrs(refAttrs);
  }