I have a Parent and Child entities like below -
class Parent { Long id; List<Child> children; } class Child { Long id; String status; // ACTIVE or INACTIVE Parent parent; } I would like to fetch the parent along with all its children having status=ACTIVE property.
public interface ParentRepository<Parent, Long> { Parent findByIdAndChildStatus(@Param("id") id, @Param("childStatus") status); } Question is -
- What is the easiest way to fetch only
ACTIVEchildren? - Is it possible to set ACTIVE query condition on the
Childentity'sstatusproperty to fetch only active child entities by default? - Will something like above query method work?