I have entities:
class Parent {
...
@OneToMany(Fetch = FetchType.EAGER)
@OrderBy("id")
private List<Child> children;
}
class Child{
...
@OneToMany(Fetch = FetchType.LAZY)
@OrderBy("id")
private List<GrandChild> grandChildren;
}
class GrandChild {
...
}
I want to query for paginated childs and also fetch grand childrens. I also filter childrens by name, but I don't think it's important. I have such JPQL query:
@Query("select c " +
"from Parent p " +
"inner join p.children c " +
"inner join fetch c.grandchildren g " +
"where p = :parent and " +
"c.childName like concat(:childName,'%')")
Page<Expense> findBy(@Param("parent") Parent parent, @Param("childName")String childName, Pageable pageable);
And during starting spring boot application exception is thrown:
query specified join fetching, but the owner of the fetched association was not present in the select list
Message is straightforward, however i can't add parent to select statement cause i want only children.