File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate child set didn't deleting the objects when updating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate child set didn Watch "hibernate child set didn New topic
Author

hibernate child set didn't deleting the objects when updating

vijay chaudhary
Greenhorn

Joined: Aug 21, 2006
Posts: 4
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

Put the inverse="true" on the many side of the relationship, so in the Child mapping.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate child set didn't deleting the objects when updating