title: NHibernate one-to-many generates insert and update
body: <p>Hi I have Request class which contains Document one-to-many mapping.</p>
  
  <p>Request class</p>
  
  <pre><code>public class Request
  {
  virtual public int Id
      {
          get;
          set;
      }
  ...
  virtual public Iesi.Collections.Generic.ISet&lt;Document&gt; Documents
    {
         get;
         set;
    }
  }
  </code></pre>
  
  <p>Document class</p>
  
  <pre><code>public class Document
  {
  public virtual int Id
  {
      get;
      set;
  }
  
  public virtual int ParentEntityId
  {
      get;
      set;
  }
  }
  </code></pre>
  
  <p>XML Mapping looks like this:
  REQUEST</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
      assembly="xxxx"
      namespace="xxxx.Domain"&gt;
  &lt;class name="Request" table="tbl_Req"&gt;
      &lt;id name="Id" column="req_id"&gt;
      &lt;generator class="native"&gt;&lt;/generator&gt;
          &lt;/id&gt;
      &lt;set name="Documents" cascade="all-delete-orphan"  inverse="false"&gt;
          &lt;key column="doc_parent_ent_id" not-null="true"/&gt;
              &lt;one-to-many class="xxxx.Domain.Document"/&gt;
      &lt;/set&gt;
  &lt;/class&gt;  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>DOCUMENT looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
      assembly="xxxx"
      namespace="xxxx.Domain"&gt;
  &lt;class name="Document"  table="tbl_doc"&gt;
  &lt;id name="Id" column="doc_id"&gt;
      &lt;generator class="native"&gt;&lt;/generator&gt;
  &lt;/id&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Now at this configuration when I save document NHibernate creates</p>
  
  <pre><code>INSERT INTO tbl_doc (doc_digimage_code, doc_lnk_filename, doc_lnk_filepath, doc_timestamp, doc_author, doc_parent_ent_id) VALUES (@p0, @p1, @p2, @p3, @p4, @p5); select SCOPE_IDENTITY()',N'@p0 nvarchar(4000),@p1 nvarchar(4000),@p2 nvarchar(4000),@p3 datetime,@p4 int,@p5 int',@p0=N'1',@p1=NULL,@p2=NULL,@p3='2013-02-28 18:05:45',@p4=7353,@p5=174
  </code></pre>
  
  <p>and</p>
  
  <pre><code>UPDATE tbl_doc SET doc_parent_ent_id = @p0 WHERE doc_id = @p1',N'@p0 int,@p1 int',@p0=174,@p1=32
  </code></pre>
  
  <p>I dont unerstand why NHibernate generates INSERT and UPDATE when its updating field which already has correct value.</p>
  
  <p>I also found this post <a href="https://stackoverflow.com/questions/4285386/nhibernate-insert-generates-updates-for-collection-items">NHibernate insert generates updates for collection items</a>
  which is suggesting using inverse, but when I add it to mapping then ParentEntityId is  filled with 0.</p>
  
  <p>Thanks</p>