code: protected <OTHER, X> Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter,
          SingularAttribute<? super ENTITY, OTHER> reference,
          SingularAttribute<OTHER, X> valueField) {
          if (filter.getEquals() != null) {
              return equalsSpecification(reference, valueField, filter.getEquals());
          } else if (filter.getIn() != null) {
              return valueIn(reference, valueField, filter.getIn());
          } else if (filter.getSpecified() != null) {
              return byFieldSpecified(reference, filter.getSpecified());
          }
          return null;
      }
docs: Helper function to return a specification for filtering on one-to-one or many-to-one reference. Usage:
  <pre>
  Specification&lt;Employee&gt; specByProjectId = buildReferringEntitySpecification(criteria.getProjectId(),
  Employee_.project, Project_.id);
  Specification&lt;Employee&gt; specByProjectName = buildReferringEntitySpecification(criteria.getProjectName(),
  Employee_.project, Project_.name);
  </pre>
  
  @param filter     the filter object which contains a value, which needs to match or a flag if nullness is
  checked.
  @param reference  the attribute of the static metamodel for the referring entity.
  @param valueField the attribute of the static metamodel of the referred entity, where the equality should be
  checked.
  @param <OTHER>    The type of the referenced entity.
  @param <X>        The type of the attribute which is filtered.
  @return a Specification