title: NHibernate one-to-many could not insert null key
body: <p>I'm trying to use NHibernate. I have these following tables:</p>
  
  <pre class="lang-sql prettyprint-override"><code>    CREATE TABLE person(person_id INTEGER IDENTITY(1,1) NOT NULL,  
      person_first_name VARCHAR(55) NOT NULL,  
      person_last_name VARCHAR(55) NULL,   
      person_contacted_number INTEGER NOT NULL, 
      person_date_last_contacted DATETIME NOT NULL,
      person_date_added DATETIME NOT NULL,  
      CONSTRAINT PK_person PRIMARY KEY (person_id));
  
      CREATE TABLE person_order(order_id INTEGER IDENTITY(1,1) NOT NULL,  
      order_person_id INT NOT NULL,  
      CONSTRAINT PK_person PRIMARY KEY (order_id)),
      CONSTRAINT FK_person_order_person FOREIGN KEY(order_person_id)
      REFERENCES person (person_id);
  </code></pre>
  
  <p>Classes:</p>
  
  <pre><code>    public class Person
      {
          public virtual int person_id { get; set; }
          public virtual String person_first_name { get; set; }
          public virtual String person_last_name { get; set; }
          public virtual int person_contacted_number { get; set; }
          public virtual DateTime person_date_last_contacted { get; set; }
          public virtual DateTime person_date_added { get; set; }
          public virtual ISet&lt;PersonOrder&gt; person_orders { get; set; }
      }
      public class PersonOrder
      {
          public virtual int order_id { get; set; }
          public virtual int order_person_id { get; set; }
          public virtual Person Person { get; set; }
      }
  </code></pre>
  
  <p>hbm.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>  &lt;class name="Person" table="`person`"&gt;
          &lt;id name="person_id"&gt;
            &lt;generator class="native"/&gt;
          &lt;/id&gt;
          &lt;property name="person_first_name" /&gt;
          &lt;property name="person_last_name" /&gt;
          &lt;property name="person_contacted_number" /&gt;
          &lt;property name="person_date_last_contacted" /&gt;
          &lt;property name="person_date_added" type="LocalDateTime" /&gt;
          &lt;set name="person_orders" table="`person_order`" cascade="all-delete-orphan" inverse="true"&gt;
            &lt;key column="order_person_id"/&gt;
            &lt;one-to-many class="PersonOrder"/&gt;
          &lt;/set&gt;
    &lt;/class&gt;
  
    &lt;class name="PersonOrder" table="`person_order`"&gt;
       &lt;id name="order_id"&gt;
        &lt;generator class="native"/&gt;
      &lt;/id&gt;
      &lt;many-to-one name="Person" column="order_person_id" cascade="save-update" /&gt;
    &lt;/class&gt;
  </code></pre>
  
  <p>I want to save Person to database (cascade):</p>
  
  <pre><code>var newPerson = CreatePerson(); // return new Person
  newPerson.person_orders = new HashedSet&lt;PersonOrder&gt; {new PersonOrder()};
  session.Save(newPerson);
  </code></pre>
  
  <p>And have a error could not insert:</p>
  
  <pre><code>[TestConsoleApplication.PersonOrder][SQL: INSERT INTO [person_order] (order_person_id) VALUES (?); select SCOPE_IDENTITY()]
  </code></pre>
  
  <p>I think it's not correct one-to-many mapping for class. How to resolve this?</p>