-->
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.  [ 8 posts ] 
Author Message
 Post subject: many-to-many inverse=true and delete
PostPosted: Tue Oct 28, 2003 1:09 pm 
Beginner
Beginner

Joined: Tue Oct 28, 2003 12:09 pm
Posts: 46
I have a many-to-many bidirectional mapping and am deleting an object from the inverse=true side of the equation. When I do that, the row in the join table is not deleted.

In the documentation it says:
"Changes made only to the inverse end of the association are not persisted."

Does that hold true for join table info or is my mapping screwed up?


Heres' the mapping:

MemberList.hbm.xml

<bag name="members" table="memberList_to_member" cascade="save-update" inverse="true" lazy="true">
<key column="memberListId"/>
<many-to-many class="org.groundspring.emailnow.model.Member" column="memberId"/>
</bag>


Member.hbm.xml
<set name="memberLists" table="memberList_to_member" lazy="true">
<key column="memberId"/>
<many-to-many class="org.groundspring.emailnow.model.MemberList" column="memberListId"/>
</set>

And it's hibernateSession.delete(memberList) that I'm calling.

I'm using hibernate 2.0.1 if that matters. I haven't had time to upgrade yet.

Thanks,
-mp


Top
 Profile  
 
 Post subject: Re: many-to-many inverse=true and delete
PostPosted: Tue Oct 28, 2003 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mpopetz wrote:
Does that hold true for join table info or is my mapping screwed up?

Yes

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 1:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Does that hold true for join table info

Thats exactly what inverse="true" means for a many-to-many association (i.e., with an association table). Changes to the side marked inverse="true" will not effect the entries in the association table.

Quote:
And it's hibernateSession.delete(memberList) that I'm calling.

So is that trying to delete an instance of MemberList? If so, adn you want it ti also delete the related entries in the memberList_to_member table, set the cascaed attribute on MemberList.members to "all"...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 8:54 am 
Beginner
Beginner

Joined: Tue Oct 28, 2003 12:09 pm
Posts: 46
won't cascade="all" cause my members to be deleted as well? I only want the links to be deleted...

-mp


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
To delete all links of a many-to-many association, just dereference it.

Of course, you must use inverse="false".


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 9:23 am 
Beginner
Beginner

Joined: Tue Oct 28, 2003 12:09 pm
Posts: 46
I went ahead and dereferenced it from the inverse="false" side of things as a quick fix to my problem, but I guess my question boils down to:

If hibernate is told to delete an object, shouldn't it clean up join tables that it is handling? Otherwise it is leaving invalid data in a table and referenced from another object.

Is there a reason not to handle this case for users?

I'm trying to come up with a reason where a user would want to leave the reference there even though the data is invalid (and hibernate will ObjectNotFound if you try to load a collection with a reference to the deleted object).

Thoughts?
-mp


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 9:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are, of course, supposed to remove the object you are deleting from any collections it belongs to, before deleting it. If you are using any other database than MySQL, you will get a FK violation if you do not.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 3:29 am 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
Can a hibernate expert please comment on why this shouldn't be implemented?

Quote:
If hibernate is told to delete an object, shouldn't it clean up join tables that it is handling? Otherwise it is leaving invalid data in a table and referenced from another object.

Is there a reason not to handle this case for users?

I'm trying to come up with a reason where a user would want to leave the reference there even though the data is invalid


I understand the inverse property and why the association shouldn't be updated twice. But when deleting the item, it seems like deleting either end of the Many-to-Many association should also remove the association.

Thanks!


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