title: Hibernate one-to-many : On update, changed children are not updated
body: <p>I have a one-to-many relationship as below - </p>
  
  <p>Parent hbm:-</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="ParentClass" table="PARENT_TABLE" schema="schemaname" lazy="false"&gt;
  
          &lt;cache usage="read-write" /&gt;
  
          &lt;id name="id" column="PARENT_ID_ID" type="java.lang.Long"&gt;
              &lt;generator class="sequence"&gt;
                  &lt;param name="sequence"&gt;schemaname.parent_sequence_name&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
  
          &lt;version name="versionNumber" column="version_num" type="java.lang.Long" insert="false" /&gt;
          &lt;property name="recordStatus" column="RECORD_STATUS" type="java.lang.String" insert="false" /&gt;
  
          &lt;list name="children" cascade="all-delete-orphan"&gt;
              &lt;key column="PARENT_ID" /&gt;
              &lt;list-index column="LINE_NUMBER" /&gt;
              &lt;one-to-many class="ChildClass" /&gt;
          &lt;/list&gt;
  
          &amp;audit;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Child hbm:-</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="ChildClass" table="CHILD_TABLE" schema="schemaname" lazy="false"&gt;
  
          &lt;id name="id" column="CHILD_ID" type="java.lang.Long"&gt;
              &lt;generator class="native"&gt;
                  &lt;param name="sequence"&gt;schema.child_sequence_name&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
  
          &lt;version name="versionNumber" column="VERSION_NUMBER" type="java.lang.Long" /&gt;
          &lt;property name="recordStatus" column="RECORD_STATUS" type="java.lang.String" /&gt;
          &lt;property name="lineNumber" column="LINE_NUMBER" type="java.lang.Long" /&gt;
          &lt;many-to-one name="parent" column="PARENT_ID" class="ParentClass" fetch="select" /&gt;
      &amp;audit;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I am entering the parent and children in a form and getting into an action class using Struts. The action class does the .saveOrUpdate(parent).</p>
  
  <pre><code>sessionFactory.getCurrentSession().saveOrUpdate(parent); 
  </code></pre>
  
  <p>When I insert a new parent, it inserts the children fine. After inserting, I shift the control back to the form with the same values. Then, I change some values on a child and submit it again. In this case, I can see (from hibernate logs) that the parent is updated, but the changed child is not updated. </p>
  
  <p>Is there an option in Hibernate to force the changed children to get updated when the parent is updated? If only the changed children cannot be updated, I am ok with all the children getting updated.</p>
  
  <p>If this information is not enough to understand what I am trying to do, please let me know and I will give more information. </p>
  
  <p>Thanks in advance</p>
  
  <p>UPDATE:- </p>
  
  <p>I just noticed that Hibernate is throwing this exception on the child records while trying to update :- </p>
  
  <pre><code>Could not synchronize database state with session
  org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.efleets.services.billing.domain.InvoiceBulk#206]
      at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1761)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2403)
      at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2303)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2603)
      at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      at com.efleets.services.common.integration.GenericDAOImpl.flush(GenericDAOImpl.java:115)
  </code></pre>
  
  <p>Thanks. Any help will be appreciated.</p>