title: Removing child from collection using JPA
body: <p>I'm using JPA over Hibernate in my web-app. Here are two entities (only getters are shown):</p>
  
  <pre><code>class Child {
    private Parent parent;
  
    @ManyToOne(optional=false)
    @JoinColumn(name="parent_id", referencedColumnName="parent_id", nullable=false, updatable=false)
    public Parent getParent() {
      return parent;
    }
  }
  
  class Parent {
    private Collection&lt;Child&gt; children;
  
    @OneToMany(fetch=FetchType.EAGER, mappedBy="parent", cascade={CascadeType.ALL})
    public Collection&lt;Child&gt; getChildren() {
      return children;
    }
  }
  </code></pre>
  
  <p>As you see <code>Parent</code> and <code>Child</code> relate as "one-to-many".</p>
  
  <p>Now I need to load a <code>Parent</code> instance, remove some or all children and save the changes. Below is code which  does not work for me:</p>
  
  <pre><code>Parent p = entityManager.find(Parent.class, 12345L); // load entity
  p.getChildren().clear(); // remove all children
  entityManager.merge(p); // try to save
  </code></pre>
  
  <p>Child entities are not remove in the example above. Now I have to manually call <code>entityManager.remove()</code> for each child.</p>
  
  <p>Is there any easier way to manage child collection?</p>
  
  <p>Please notice that I don't want to use Hibernate-specific functionality, only pure JPA.</p>