title: Entity graph on many-to-many relation loading entities multiple times - Spring Data JPA
body: <p>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 <code>EntityGraphs</code>.</p>
  
  <p>Here is the parent with annotation.</p>
  
  <pre><code>@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&lt;Child&gt; children;
  </code></pre>
  
  <p>Here is the code in repository for parent.</p>
  
  <pre><code>    @EntityGraph(value = "Parent.children", type = EntityGraphType.LOAD)
  public List&lt;Parent&gt; findAll(Predicate predicate);
  </code></pre>
  
  <p>I have many to many relationship between two of my entities. But I want to get result like</p>
  
  <pre><code>parent1 {
  child1,
  child2
  }
  </code></pre>
  
  <p>But I am getting parents for each combination..</p>
  
  <pre><code>Parent1 {
  child1,
  child2
  }
  
  Parent1 {
  child1,
  child2
  }
  </code></pre>
  
  <p>there I get parent2.</p>
  
  <p>But what I want is to get the parent1 only once, not repeating.
  While using entity graph.</p>