title: Hibernate Unidirectional ManyToMany Update Target Constituent Relation
body: <p>There is a unidirectional <code>ManyToMany</code> mapping between <code>Role</code> and <code>Privilege</code> with <code>Role</code> as the owning entity like so</p>
  
  <p><code>Role</code></p>
  
  <pre><code>@Entity
  public class Role extends BaseEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "role_id")
      private Integer roleId;
      @Size(max = 45)
      @Column(name = "role")
      private String role;
  
      @JoinTable(name = "role_privilege", joinColumns = {
              @JoinColumn(name = "role_role_id", referencedColumnName = "role_id")}, inverseJoinColumns = {
              @JoinColumn(name = "privilege_privilege_id", referencedColumnName = "privilege_id")})
      @ManyToMany(
              cascade = {
                  CascadeType.DETACH,
                  CascadeType.MERGE,
                  CascadeType.REFRESH,
                  CascadeType.PERSIST }, fetch = FetchType.EAGER, targetEntity = Privilege.class)
      private Collection&lt;Privilege&gt; privilegeCollection;
  
      @Transient
      private Collection&lt;Privilege&gt; parentPrivilegeCollection;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "roleId")
      @JsonIgnore
      private Collection&lt;User&gt; userCollection;
  
      public Role() {
      }
      //getters,setter,hashcode,equals removed for brevity
  }
  </code></pre>
  
  <p><code>Privilege</code></p>
  
  <pre><code>@Entity
  public class Privilege extends BaseEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "privilege_id")
      private Integer privilegeId;
      @Size(max = 45)
      @Column(name = "name")
      private String name;
      @Size(max = 150)
      @Column(name = "description")
      private String description;
      @Size(max = 45)
      @Column(name = "friendly_name")
      private String friendlyName;
      @JoinTable(name = "privilege_hierachy", joinColumns = {
              @JoinColumn(name = "parent_privilege", referencedColumnName = "privilege_id")}, inverseJoinColumns = {
              @JoinColumn(name = "child_privilege", referencedColumnName = "privilege_id")})
      @ManyToMany
      private Collection&lt;Privilege&gt; privilegeCollection;
  
      public Privilege() {
      }
  }
  </code></pre>
  
  <h1>The Problem</h1>
  
  <p>Whenever i set updated list of privileges  in a role and update, the join table is successfully updated without removing either target or owning entity, and that is desired result. The problem is on update it also affect another self join table in <code>Privilege</code> called <code>privilege_hierachy</code> which is not what is expect.</p>
  
  <p>Is it possible for hibernate to only update the <code>Role</code>-<code>Privilege</code> mant-to-many relationship and let other relation unchanged.</p>
  
  <p>Spring Data Jpa is used for data persistence</p>