title: NHibernate: Could not delete collection: Cannot insert the value NULL
body: <p>There's a <code>ResourcePackage</code> class and a <code>PackageItem</code> class:</p>
  
  <pre><code>public ResourcePackageMap()
  {
      DiscriminatorValue((int)ResourceObjectType.Package);
  
      HasMany(x =&gt; x.Children).KeyColumn("AggregationObjectId").Cascade.AllDeleteOrphan();
  }
  
  public PackageItemMap()
  {
      Id(x =&gt; x.Id, "AggregationLinkId");
      References(x =&gt; x.ResourceItem, "ChildObjectId");
      References(x =&gt; x.Package, "AggregationObjectId");
      Map(x =&gt; x.Order, "OrderWithinAggregation");
      Map(x =&gt; x.Usage, "Usage");
  
      Table("tbl_Object_Aggregation_Link");
  }
  </code></pre>
  
  <p>I got an error saying:</p>
  
  <pre>
  could not delete collection: [Domain.ResourcePackage.Children#102c589b-fc1c-451d-8300-a0ef00baa21f][SQL: 
  UPDATE tbl_Object_Aggregation_Link SET AggregationObjectId = null WHERE AggregationObjectId = @p0]
  
  NHibernate.Exceptions.GenericADOException: could not delete collection: 
  [Domain.ResourcePackage.Children#102c589b-fc1c-451d-8300-a0ef00baa21f]
  [SQL: UPDATE tbl_Object_Aggregation_Link SET AggregationObjectId = null WHERE 
  AggregationObjectId = @p0] ---> System.Data.SqlClient.SqlException: 
  Cannot insert the value NULL into column 'AggregationObjectId', 
  table 'KDatabase.dbo.tbl_Object_Aggregation_Link'; 
  column does not allow nulls. 
  UPDATE fails.  The statement has been terminated.
  </pre>
  
  <p>The relationship table runs as follow:</p>
  
  <p>There's a tbl_Object table and a tbl_Object_Aggregation_Link table, which contains two foreign keys to tbl_Object table.</p>
  
  <p>And the mapping class of tbl_Object_Aggregation_Link table is:</p>
  
  <pre><code>public class PackageItemMap : ClassMap&lt;PackageItem&gt;
  {
      public PackageItemMap()
      {
          Id(x =&gt; x.Id, "AggregationLinkId");
          References(x =&gt; x.ResourceItem, "ChildObjectId");
          References(x =&gt; x.Package, "AggregationObjectId");
          Map(x =&gt; x.Order, "OrderWithinAggregation");
          Map(x =&gt; x.Usage, "Usage");
  
          Table("tbl_Object_Aggregation_Link");
      }
  }
  </code></pre>