Search code examples
javahibernatequerydsl

How to find all entities whose linked collection of entities contains at least one element from my list?


I want to find all entities Foo, whose Bar linked entities (via many-to-many relation) contains at least one element from my input Set.

@Override
public Set<Foo> findFoosHavingAtLeastOneBar(Set<Bar> bars) {
    QFoo foo = QFoo.foo;

    Predicate predicate = foo.bars. //I'm stuck here

}

When doing Ctrl + Space I can't find anything that could help me achieve this.

Is it possible to do that in a single Hibernate request?


Solution

  • You can extract set of foo from your input bars and then add all the sets from there to another set to remove duplicates.