Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate child set didn't deleting the objects when updating

 
vijay chaudhary
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have following script in parent hbm file for child as:

<set name="child" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="ChildId"/>
<one-to-many column="ParentId" class="Child"/>
</set>

the problem is when i update the child with parent or insert more childrens so there is no problem. but when i update the parent with child. if child insertable or updatable so it perform that tasks. and if some child is deleted in the sets so it does't deleted the childs.

for example

i insert the record Parent with child

Parent p = new Parent("1001");
p.addChild(new Child("201"));
p.addChild(new Child("202"));
p.addChild(new Child("203"));

--- open session ----
session.save(p);
--- close session ----


so it save parent with three childs.

and after this task when i update this record as per following.

Parent p = new Parent("1001");
p.addChild(new Child("201"));
p.addChild(new Child("203"));
p.addChild(new Child("204"));

--- open session ----
session.update(p);
--- close session ----


so it add more one child according with parent. but not delete the child have id"202".

my problem is this. pls give me proper answer or example very very thanks in advance for this solutions.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the inverse="true" on the many side of the relationship, so in the Child mapping.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic