title: java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities
body: <p>I have 3 entities with ManyToMany relationships:</p>
  
  <p><strong>Role Entity:</strong></p>
  
  <pre><code>@Entity
  public class Role {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer roleID;
      private String roleName;
      private String description;
  
      @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
      @JoinTable(name = "role_permission", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "permission_id")})
      private Set&lt;Permission&gt; permissions = new LinkedHashSet&lt;Permission&gt;();
  }
  </code></pre>
  
  <p><strong>Permission Entity:</strong></p>
  
  <pre><code>@Entity
  public class Permission {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int permissionID;
      private String permissionName;
      private String description;
  
      @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
      @JoinTable(name = "permission_functionality", joinColumns = {@JoinColumn(name = "permission_id")}, inverseJoinColumns = {@JoinColumn(name = "functionality_id")})
      private Set&lt;Functionality&gt; functionalities = new LinkedHashSet&lt;&gt;();
  }
  </code></pre>
  
  <p><strong>Functionality Entity:</strong></p>
  
  <pre><code>@Entity
  public class Functionality {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;
      private String name;
  }
  </code></pre>
  
  <p>I did the following:</p>
  
  <ol>
  <li><p>I have created 3 functionalities:</p>
  
  <pre><code>Functionality1, Functionality2, Functionality3
  </code></pre></li>
  <li><p>Then created 2 permissions:</p>
  
  <pre><code>Permission1 with Functionality1, Functionality2
  
  Permission2 with Functionality2, Functionality3
  </code></pre></li>
  <li><p>Then created a role:</p>
  
  <pre><code>Role1 with Permission1 and Permission2 
  </code></pre></li>
  </ol>
  
  <p>I am getting the following exception:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Multiple representations of the same entity [com.persistence.entity.admin.Functionality#1] are being merged. Detached: [com.persistence.entity.admin.Functionality@4729256a]; Detached: [com.persistence.entity.admin.Functionality@56ed25db]</p>
  </blockquote>