title: One to Many relationship JPA/Hibernate removing links
body: <p>I have bidirectional relationship setup as follows:</p>
  
  <pre><code>class Child{
      @ManyToOne
      @JoinTable(name = "CHILDREN_WITH_PARENT", 
              joinColumns = {@JoinColumn(name = "CHILD_ID")}, 
              inverseJoinColumns = {@JoinColumn(name = "PARENT_ID")}
      )
      private Parent parent;
  }
  
  class Parent{
      @OneToMany(mappedBy="parent", cascade=CascadeType.ALL)
      Set&lt;Child&gt; childrens = new HashSet&lt;Child&gt;();
  
      public void persistOrMerge() {
          EntityManager em = entityManager();
          em.getTransaction().begin();
          try {
              if (em.contains(this))
                  return;
              if (id == null || id == 0) {
                  this.setCreatedDate(new Date());
                  em.persist(this);
              } else {
                  Parent prev = em.find(Parent.class, this.id);
                  if (prev == null) {
                      em.persist(this);
                  } else{
                      this.setCreatedDate(new Date());
                      em.merge(this);
                  }
              }
              em.flush();
              em.getTransaction().commit();
  
          }  finally {
              em.close();
  
          }
      }
  
  }
  </code></pre>
  
  <p>On my client side I have following code (GWT + EntityProxy)</p>
  
  <pre><code>Set&lt;ChildProxy&gt; children  = new HashSet&lt;ChildProxy&gt;();
  if(childIsNew)
     child = request.create(Children.class)
  else
     child = request.edit(oldChild)
  children.add(child);
  //If children are deleted, they are not contained in the set
  //we are sending back to server
  parent.setChildren(children)
  parent.persistOrMerge();
  </code></pre>
  
  <p><strong>This code only works for adding new children. Removing of children from parent does not work even if parent class receives an empty children set. The linkages in JOIN table are not removed.</strong></p>
  
  <p>Can you please tell where I am missing something?</p>
  
  <p>Thanks!</p>