title: JPA many to many - do i have to remove\add from both collection sets?
body: <p>I have a User entity,
  And a Department Entity</p>
  
  <p>i want to have @manyToMany relationship between them : </p>
  
  <p>many users can have many departments.</p>
  
  <p>in my User entity:</p>
  
  <pre><code>@ManyToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "UserDepartments", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "department_id", referencedColumnName = "id") })
  private Set&lt;Department&gt; departments;
  </code></pre>
  
  <p>and my Department entity has a SET as well of users..</p>
  
  <p>my question is:</p>
  
  <p>if i need to implement the method :</p>
  
  <pre><code>public void removeUserFromDepartment(User user, Department department) {
        //bla bla
  }
  </code></pre>
  
  <p>do i have to call</p>
  
  <pre><code>department.getUserCollection.remove(user);
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>user.getDepartmentCollection.remove(department);
  </code></pre>
  
  <p>Or is there a way to maintain this logic by only removing one of them ?</p>
  
  <p>If i have to save both its pretty hard to maintain especially for someone who doesn't know about the many to many relation of the two entities..</p>