I have below entities:
public class Category {
private Integer id;
@OneToMany(mappedBy = "parent")
private List<Topic> topics;
}
public class Topic {
private Integer id;
@OneToMany(mappedBy = "parent")
private List<Posts> posts;
@ManyToOne
@JoinColumn(name = "id")
private Category parent;
}
public class Post {
private Integer id;
@ManyToOne
@JoinColumn(name = "id")
private Topic parent;
/* Post fields */
}
and I want fetch all categories with joined topics and joined posts using JPQL query. I was wrote query like below:
SELECT c FROM Category c JOIN FETCH c.topics t JOIN FETCH t.posts p WHERE ...
But I got the error
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
I found articles about this error, but these articles only describe situation where in one entity are two collections to join. My problem is a little different and I don't know How to solve it.
It is possible to do in one query?
Sorry for my bad english, but I usually speak in other language