Reputation: 397
I need to find matching entities where the parent entity has a list within it, I will pass in a list of Ids as a parameter and I want to match any parent entity where the inner list contains any of the parameter Ids, can this be done without a predicate approach? Something along the lines of the following which I know wont work but would appreciate any pointers, have read http://docs.spring.io/spring-data/jpa/docs/current/reference/html/ and this scenario is not covered.
@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;
Upvotes: 1
Views: 1716
Reputation: 7950
If you use Spring JPA you can do something like :
@Repository
public interface ParentRepository extends CrudRepository<Parent, Long> {
Boolean existsCountByChildrenIn(List<Integer> ids);
}
Upvotes: 1