-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate version 2.1
PostPosted: Thu Mar 29, 2007 2:16 pm 
Newbie

Joined: Thu Mar 29, 2007 2:05 pm
Posts: 3
i have following situation

grandParent --> has set of parents
each Parent -- > has set of children

relation between grandParent and Parent is cascade = "all-delete-orphan" and inverse="true"

relation between Parent and its children is cascade = "all-delete-orphan" and inverse="true"

now when i set Parent.clear() -- > trying to remove all its children, hibernate deletes all records from children table,

but how do i tell hibernate to delete that particular Parent from grandParent table. it does not delete records from Parent table.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 2:22 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
session.delete(parent) should work. Isnt it working?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 2:25 pm 
Newbie

Joined: Thu Mar 29, 2007 2:05 pm
Posts: 3
actually all i am doing is session.saveOrUpdate(grandParent)

and because of relations it delets all children from parent but does not delete that empty parent from grandparent.

do i need to delete each empty(no children) parent manually ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 2:38 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Clearing the parent list would simply remove the link.

Since your objective in this scenario is really to delete the parent objects, simply call
session.delete(parent)
This would delete the children also.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 11:30 am 
Newbie

Joined: Thu Mar 29, 2007 2:05 pm
Posts: 3
Here is what I am trying.

Grandparent gp = (Grandparent)session.load(Grandparent.class, pid);
Set <Parent> p = gp.getParent();
Set <Child> c = p.getChildren();

//This works, and removes specified children from database
p.getChildren().remove(0); //With iterator
p.getChildren().remove(1); //With iterator
session.update(gp);

//This does not remove any parent from the database
gp.getParent().remove(0); //With iterator
gp.getParent().remove(1); //With iterator
session.update(gp);



So my only confusion is, if removing children from parent causes hibernate to delete children, why not removing the parent from grandparent cause hibernate to delete parent?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.