title: NHibernate Mapping problem
body: <p>My database is being driven by my NHibernate mapping files.</p>
  
  <p>I have a Category class that looks like the following :</p>
  
  <pre><code>public class Category {
  
          public Category() : this("") { }
  
          public Category(string name) {
              Name = name;
              SubCategories = new List&lt;Category&gt;();
              Products = new HashSet&lt;Product&gt;();
          }
  
  
          public virtual int ID { get; set; }
          public virtual string Name { get; set; }
          public virtual string Description { get; set; }
          public virtual Category Parent { get; set; }
          public virtual bool IsDefault { get; set; }
          public virtual ICollection&lt;Category&gt; SubCategories { get; set; }
          public virtual ICollection&lt;Product&gt; Products { get; set; }   
  </code></pre>
  
  <p>and here is my Mapping file : </p>
  
  <p>
  </p>
  
  <p>
      
        
      
      </p>
  
  <pre><code>&lt;property name="Name" column="Name" type="string" not-null="true"/&gt;
  &lt;property name="IsDefault" column="IsDefault" type="boolean" not-null="true" /&gt;
  &lt;property name="Description" column="Description" type="string" not-null="true" /&gt;
  
  &lt;many-to-one name="Parent" column="ParentID"&gt;&lt;/many-to-one&gt;
  
  &lt;bag name="SubCategories" inverse="true"&gt;
    &lt;key column="ParentID"&gt;&lt;/key&gt;
    &lt;one-to-many class="Category"/&gt;
  &lt;/bag&gt;
  &lt;set name="Products" table="Categories_Products"&gt;
    &lt;key column="CategoryId"&gt;&lt;/key&gt;
    &lt;many-to-many column="ProductId" class="Product"&gt;&lt;/many-to-many&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>when I try to create the database I get the following error :</p>
  
  <p>failed: The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK9AD976763BF05E2A". The conflict occurred in database "CoderForTraders", table "dbo.Categories", column 'CategoryId'.
  The statement has been terminated.</p>
  
  <p>I looked on the net for some answers but found none.
  Thanks for your help</p>
  
  <p>Here is the missing part :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CBL.CoderForTraders.DomainModel" namespace="CBL.CoderForTraders.DomainModel" default-access="field.camelcase-underscore" default-lazy="true"&gt;
  
    &lt;class name="Category" table="Categories" &gt;
      &lt;id name="_persistenceId" column="CategoryId" type="Guid" access="field" unsaved-value="00000000-0000-0000-0000-000000000000"&gt;
        &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;version name="_persistenceVersion" column="RowVersion" access="field" type="int" unsaved-value="0" /&gt;
  </code></pre>