简体   繁体   中英

JPQL (JPA) Find Object if list have intersection

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

尝试以下(我没试过):

SELECT DISTINCT(a) FROM ClassA a, ClassB b INNER JOIN a.labels labelA INNER JOIN b.labels labelB WHERE labelA = labelB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM