-->
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.  [ 4 posts ] 
Author Message
 Post subject: Savind single objects in a graph
PostPosted: Wed Mar 24, 2004 1:05 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
Ok, I've been reading through all of the manuals for the fourth time, but I cannot find a definitive conclusion on my current issue.

I have a parent child relation like this:

grandparent 1 ---- 0..* parent 1 ----- 0..* child

So all the classes have a bi-directional relationship with both their chhildren and their parent.

The thing I want to accomplish is the following.

If the class "parent" is passed to the DAO code I want to save the following:
- fields in the class "parent"
- relationship with "grandparent"

I do not want to save these values:
- fields in "grandparent"
- relationship with "child"
- fields in "child"

If parent is deleted I do want to remove all children. (same for grandparent)

This is all due to the fact that security is always checked for one layer, so the dao will check if you may add a parent to grandparent, but will not check if you may edit all the children to save database queries.

So in order to delete a child, you will have to remove it from the db, and the relationship with the parent should be removed aswell.

If you remove a child from the set in parent and save the parent, nothing should happen.

Is this possible with a combination of inverse and cascade? I was thinking of the following:

grandparent -> parent
inverse = true
cascade = delete

parent -> grandparent
inverse = false
cascade = none
not-null = true

parent -> child
inverse = true
cascade = delete

child -> parent
inverse = false
cascade = none
not-null = true

This way I think it should be possible to return a parent with an incomplete list of children and call save to the parent without actually deleting any children, while still updating the reference to grandparent. Am I correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 1:46 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
After a lot of testing I can say that this actually works.

Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
And what about giving your solution? this might help a lot of people here....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 4:12 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
The solution is described above.

You need to save each child seperately, but that fits in out data model. And every parent may have an incomplete set of children which will not result deletion of the missing children .

I did set cascade = delete-orphan on parent -> child relation to make sure all orphaned children are deleted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.