title: JPA clear collection and add new items
body: <p>I have a @OneToMany collection (list) that I would like to clear, and add new elements to in the same transaction.</p>
  
  <p>Using </p>
  
  <pre><code>collection.clear();
  collection.add(new EntityB());
  </code></pre>
  
  <p>Simply adds the new instance, and never removes anything. I have <code>orphanRemoval = true</code> for the collection field.</p>
  
  <p>ADDED:</p>
  
  <pre><code>// Parent entity
  @OneToMany(mappedBy = "product", orphanRemoval = true)
  private List&lt;Feature&gt; features = new ArrayList&lt;&gt;();
  
  // Child entity
  @ManyToOne(cascade = CascadeType.ALL)
  private Product product;
  
  // Clear and add attempt
  product.getFeatures().clear();
  
  Feature feature = new Feature(product, ls);
  product.getFeatures().add(feature);
  </code></pre>