title: When inserting a parent and its children can Hibernate set the parent id when inserting the child rather than having to update after?
body: <p>I have two objects</p>
  
  <pre><code>public class Parent {
      int id;
      String name;
      int Set&lt;Child&gt; children;
  }
  
  public class Child {
      int id;
      String name;
      int parentId;
  }
  </code></pre>
  
  <p>With the following mapping file</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="Parent" table="parent"&gt;
          &lt;id column="id" access="field"&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;    
          &lt;property name="name" column="name" access="field" /&gt;    
          &lt;set name="children" access="property" cascade="all" lazy="true"  &gt;
              &lt;key&gt;&lt;column name="parent_id"/&gt;&lt;/key&gt;
              &lt;one-to-many class="com.hp.autonomy.corepolicy.common.dto.LexiconExpression"/&gt;
          &lt;/set&gt;
      &lt;/class&gt;
      &lt;class name="Child" table="child"&gt;
          &lt;id column="id" access="field"&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;    
          &lt;property name="name" column="name" access="field" /&gt;            
          &lt;property name="parentId" column="parent_id" access="field" not-null="true" /&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>When I save a parent with one child the sql generated looks like </p>
  
  <blockquote>
    <p>Hibernate: insert into parent (id, name) values (null, ?)</p>
    
    <p>Hibernate: insert into child (id, parent_id, name) values (null, ?, ?)</p>
    
    <p>Hibernate: update child set parent_id=? where id=?</p>
  </blockquote>
  
  <p>It seems like when hibernate inserts the child it sets the parent_id to null and then comes and updates it after. This causes problems in my database and hibernate validation, as the schema says that parent_id cannot be null. </p>
  
  <p>Is it possible to have the second insert statement use the parent_id created when inserting the parent rather than coming along later and updating the child?</p>