code: protected <OTHER, MISC, X> Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter,
                                                                                         Function<Root<ENTITY>, SetJoin<MISC, OTHER>> functionToEntity,
                                                                                         Function<SetJoin<MISC, OTHER>, Expression<X>> entityToColumn) {
          if (filter.getEquals() != null) {
              return equalsSpecification(functionToEntity.andThen(entityToColumn), filter.getEquals());
          } else if (filter.getSpecified() != null) {
              // Interestingly, 'functionToEntity' doesn't work, we need the longer lambda formula 
              return byFieldSpecified(root -> functionToEntity.apply(root), filter.getSpecified());
          }
          return null;
      }
docs: Helper function to return a specification for filtering on one-to-many or many-to-many reference.Usage:<pre>
  Specification&lt;Employee&gt; specByEmployeeId = buildReferringEntitySpecification(
  criteria.getEmployeId(),
  root -&gt; root.get(Project_.company).join(Company_.employees),
  entity -&gt; entity.get(Employee_.id));
  Specification&lt;Employee&gt; specByProjectName = buildReferringEntitySpecification(
  criteria.getProjectName(),
  root -&gt; root.get(Project_.project)
  entity -&gt; entity.get(Project_.name));
  </pre>
  
  @param filter           the filter object which contains a value, which needs to match or a flag if emptiness is
  checked.
  @param functionToEntity the function, which joins he current entity to the entity set, on which the filtering is applied.
  @param entityToColumn   the function, which of the static metamodel of the referred entity, where the equality should be
  checked.
  @param <OTHER>          The type of the referenced entity.
  @param <MISC>           The type of the entity which is the last before the OTHER in the chain.
  @param <X>              The type of the attribute which is filtered.
  @return a Specification