title: Hibernate- cascading option for one to many using spring HibernateTemplate
body: <p>In my application, I'm having a one-to-many relationship in which I have the following requirements. As an example, take Car- Owner relationship. Owner can have multiple cars, while one car can have one owner only.</p>
  
  <ul>
  <li>When I save parent entity (Owner) with car as a collection in it, I want the car to get inserted automatically. Same for update as well.</li>
  <li>When remove some car objects from the collection &amp; save, I want the  removed car objects to get deleted from the database.</li>
  </ul>
  
  <p>I tried with following options in the hibernate xml mapping:</p>
  
  <pre><code>inverse="false" fetch="select" cascade="all-delete-orphan"
  </code></pre>
  
  <p>And I inserted using</p>
  
  <pre><code>HibernateTemplate.persist()
  </code></pre>
  
  <p>Updated using</p>
  
  <pre><code>HibernateTemplate.merge()
  </code></pre>
  
  <p>The update works well, but the insert is not working properly.</p>
  
  <p>Can anybody advice me what is the exact cascade option &amp; the method to use in saving &amp; updating such scenario?</p>