-->
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: how to delete a many to many relation when child is removed
PostPosted: Fri Aug 18, 2006 6:25 am 
Newbie

Joined: Fri Oct 07, 2005 11:53 am
Posts: 9
Hi:

I have the bellow problem:

I have many-to-many relationship, but when i delete a child the relation is still alive.

For example:
[houses] 0..* <----> 0..* [owners]

The relation table is [rel_houses_owners].

When i delete a register from [owners] table i want all the registers on [rel_houses_owners] that refered to the [owners] deleted register will be deleted also.

But i dont know how to say that to hibernate.

Thanx.
d2clon


Top
 Profile  
 
 Post subject: use two one-to-many associations instead
PostPosted: Fri Aug 18, 2006 5:47 pm 
Newbie

Joined: Wed Aug 16, 2006 6:29 pm
Posts: 9
When using a many-to-many association cascade="all", cascade="delete", and cascade="all-delete-orphans" aren't meaningful. That's because you might delete an instance that can have other parents pointing to it.

If you want to delete rows from the association table (rel_houses_owners) then I would suggest using two one-to-many relationships instead of many-to-many.

You would need one-to-many from owners to house_owners and many-to-one from house_owners to owners. This will allow you to cascade deletes in owner to house_owners without deleting the owner.

Use of many-to-many often leads to the solution described above and is hence discouraged.


Top
 Profile  
 
 Post subject: Re: use two one-to-many associations instead
PostPosted: Tue Aug 29, 2006 1:52 am 
Beginner
Beginner

Joined: Tue Aug 22, 2006 3:06 am
Posts: 25
rstoya05-aop wrote:
When using a many-to-many association cascade="all", cascade="delete", and cascade="all-delete-orphans" aren't meaningful. That's because you might delete an instance that can have other parents pointing to it.

If you want to delete rows from the association table (rel_houses_owners) then I would suggest using two one-to-many relationships instead of many-to-many.

You would need one-to-many from owners to house_owners and many-to-one from house_owners to owners. This will allow you to cascade deletes in owner to house_owners without deleting the owner.

Use of many-to-many often leads to the solution described above and is hence discouraged.


no another solutions?


Top
 Profile  
 
 Post subject: YELP...........
PostPosted: Fri Dec 01, 2006 5:46 pm 
Newbie

Joined: Mon Nov 27, 2006 1:17 pm
Posts: 13
Can somebody explain how to actually go about it, because Im working on the same things as rstoya said .A relates to A_B with one-to-many and A_B relates to B with many-to-one. Things work fine for retrieval but when i try to insert data into the table it blows up giving :

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of A.A_To_B.b at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171) at .........Blah Blah.....

where b is instance of B.java.

Actually my join table is nothing but has composite key of a combination of foreign keys from A and B., And has no more columns.

Thus the composite key has A_BPK key class , which mentions about the composite-key and error comes up whenever that A_BPK.java is accessed. If somebody has gone thru the same pain ,he should come forward for my rescue.
The error is thrown at BasicPropertyAccessr and BasicGetter.

Thanks.........


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 8:14 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 4:10 pm
Posts: 38
Location: Charleston, SC
I posted mappings in another thread that show how to do it. In my case the relationship table is crew member. The one-to-many is vessel arrival -> crew member. The many-to-one is crew member -> person.

http://forum.hibernate.org/viewtopic.php?t=968048

Grant


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.