title: Hibernate and deleting from lists
body: <p>I've got two classes, ProductConfiguration and SubProduct.</p>
  
  <p>I want to replace the subproducts on the configuration, which I do in this way:</p>
  
  <pre><code>productConfiguration.getSubProducts().clear();
  productConfiguration.getSubProducts().addAll(newSubProducts);
  </code></pre>
  
  <p>In doing this, Hibernate attempts to set the ID of the parent (the product configuration) to null, and then update the row in the database. This fails, as the parent ID is a foreign key, and therefore not nullable.</p>
  
  <p>The mapping from ProductConfiguration to SubProduct:</p>
  
  <pre><code>&lt;bag name="subProducts"
       table="sub_product"
       cascade="all-delete-orphan"
       access="field"
       lazy="false"&gt;
      &lt;key column="parent_id"/&gt;
      &lt;one-to-many class="com.conscius.cpt.core.product.SubProduct"/&gt;
  &lt;/bag&gt;
  
  &lt;many-to-one name="parentProduct"
               class="com.conscius.cpt.core.product.ProductConfiguration"
               column="parent_id"
               access="field"
               not-null="true"
               cascade="none"/&gt;
  </code></pre>