• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

hibernate child set didn't deleting the objects when updating

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the inverse="true" on the many side of the relationship, so in the Child mapping.

Mark
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic