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: Many to Many delete problem
PostPosted: Thu Jan 04, 2007 8:24 am 
Newbie

Joined: Thu Jan 04, 2007 2:18 am
Posts: 4
Hi!
I have two tables (Table A and B) with a many to many relationship and an intermediate table (Table C).

The problem is that when I take a reference of table A and call it's delete method, it deletes data from Table C and Table A, but not from Table B.

Can anyone tell me a way to delete data from Table B also, if the data doesn't have any entry in the Table C.

My mapping files has the following description.
TableA.hbm.xml contains cascade="save-update"

TableB.hbm.xml contains inverse="true" cascade="save-update"

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 9:36 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
You can use the delete-orphan value for the cascade attribute.

I think you should follow the recommendation of Hibernate authors to not use many-to-many relationships by mapping the relationship table.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 1:16 am 
Newbie

Joined: Thu Jan 04, 2007 2:18 am
Posts: 4
Hi!

The problem is that, if I use cascade="save-update,delete-orphan" or "all-delete-orphan", then the data relating to other values is also deleted. e.g.

Table A: has id's 1 and 2
Table B has id's 3 and 4
and Table C (Intermediate table) has id's, one from Table A and other from Table B
1 --- 3
1 --- 4
2 --- 4

On using "all-delete-orphane" option, both the enteries from Table A, B, C are deleted, as 4 is linked with both values of Table A.

Recommendation from "Hibernate authors to not use many-to-many relationships by mapping the relationship table" is applicable if we have any additional columns in the link table, but I don't have any additional column. If I am wrong in understanding this recommendation, kindly correct me.

Waiting for reponse.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 3:24 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
The recommendation of not using many-to-many relationships is, as far as I understand, in prevision of future changes. So, they recommend their usage even if you do not have more columns.

As for the "delete-orphan" option, I understood that this was the behavior you wanted:

Quote:
The problem is that when I take a reference of table A and call it's delete method, it deletes data from Table C and Table A, but not from Table B.


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.