Reputation: 3899
I have two Classes each of which hold a list of Labels. Now I want to find every object of ClassA
that holds any item of the list of ClassB
. Is this possible with JPQL? Or using a single query?
public class ClassA {
private List<Label> labels;
}
public class ClassB {
private List<Label> labels;
}
@Repository
public interface ClassARepository extends JpaRepository<ClassA, Long> {
@Query("SELECT c FROM ClassA c WHERE :labels ____ c.labels")
public List<ClassA> findAllByLabels(@Param("labels") List<Label> labels);
}
thanks
Upvotes: 3
Views: 1562
Reputation: 19002
Try the following (I did not try it):
SELECT DISTINCT(a) FROM ClassA a, ClassB b INNER JOIN a.labels labelA INNER JOIN b.labels labelB WHERE labelA = labelB
Upvotes: 2