Sunday, June 22, 2008

About Hibernate Save and Delete parent children again

I want to add new child object into children collections and remove 'selected' existing child object from the same children collections.

  1. First, i get the collection from 'attached' parent. For e.g Set children = parent.getChildren()
  2. Add the new Child object. Of course please save the Child object first. children.add(newChild).
  3. Remove the 'selected' existing Child object. children.remove(removedChild)
  4. Finally, save the Parent object.

It is kind of fundamental. However sometimes we may get confused due to whatever reasons.

No comments:

Post a Comment