我可以查询Spring JPA @Query以查找列表与其他列表的任何匹配吗?

时间:2017-02-28 12:03:47

标签: java spring hibernate jpa

我需要找到父实体在其中有列表的匹配实体,我将传入一个Ids列表作为参数,我想匹配内部列表包含任何参数ID的任何父实体,可以这可以在没有谓词方法的情况下完成吗? 以下我知道不会工作的东西但是会欣赏任何指针,已经阅读了http://docs.spring.io/spring-data/jpa/docs/current/reference/html/并且没有涵盖这种情况。

@Query("SELECT CASE WHERE COUNT (parent) > 0 THEN 'true' ELSE 'false' END FROM Parent parent LEFT JOIN parent.children children where :ids in children")
boolean isFound(@Param("ids") List<Long> ids;

1 个答案:

答案 0 :(得分:1)

如果您使用Spring JPA,您可以执行以下操作:

@Repository
public interface ParentRepository extends CrudRepository<Parent, Long> {
    Boolean existsCountByChildrenIn(List<Integer> ids);
}