title: nHibernate Master Detail Deletion
body: <p>I have a Master Detail relationship configured. The hbm file is below. When I run some code like this</p>
  
  <pre><code>Favourite favourite = favourites.Find(f =&gt; f.Id== id);
  user.Favourites.Remove(favourite);
  m_UserRepository.Save(ref user);
  </code></pre>
  
  <p>I get the error message</p>
  
  <p><strong>NHibernate.Exceptions.GenericADOException: could not delete collection rows: [Model.Entities.User.Favourites#249][SQL: SQL not available] ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'UserId', table 'BE.Favourite'; column does not allow nulls. UPDATE fails.</strong></p>
  
  <p>Any suggestions on what this means please help.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" schema="BE" assembly="Model" default-lazy="false"&gt;
    &lt;class name="Model.Entities.User, Model" table="Users" &gt;
      &lt;id name="UserId" column="UserId" type="int" unsaved-value="0"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;property name="UserName" column="UserName" type="string" /&gt;
  
      &lt;bag name="Favourites" cascade="all" lazy="true"&gt;
        &lt;key column="UserId"/&gt;
        &lt;one-to-many class="Model.Entities.Favourite, Model"/&gt;
      &lt;/bag&gt;
  
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>