I have @ManyToMany relationship between two of my entities. When I try to load the parents with their children, the parents repeat in response payload. I want to solve my problem with EntityGraphs
.
Here is the parent with annotation.
@Entity
@Table(name="Parent_table")
@NamedEntityGraph(
name = "Parent.children",
attributeNodes = @NamedAttributeNode("children"))
public class Parent implements Serializable{
//some extra code
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="join table", joinColumns=@JoinColumn(name="key"),inverseJoinColumns=@JoinColumn(name="key"))
private List<Child> children;
Here is the code in repository for parent.
@EntityGraph(value = "Parent.children", type = EntityGraphType.LOAD)
public List<Parent> findAll(Predicate predicate);
I have many to many relationship between two of my entities. But I want to get result like
parent1 {
child1,
child2
}
But I am getting parents for each combination..
Parent1 {
child1,
child2
}
Parent1 {
child1,
child2
}
there I get parent2.
But what I want is to get the parent1 only once, not repeating. While using entity graph.