-->
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.  [ 2 posts ] 
Author Message
 Post subject: Deleting items in many-to-many associations
PostPosted: Wed Apr 20, 2005 6:09 pm 
Newbie

Joined: Wed Apr 20, 2005 6:02 pm
Posts: 1
Regarding bug: http://opensource.atlassian.com/project ... se/HHH-368

(reposting here, because I posted in the bug before, and was told to post here)

I realize this is a closed issue, but hopefully I can get a clarification that will probably help other people with the same question as mine.

It appears to me, after reading this bug report (I have the same problem as the original submittor, by the way), that the following is the case:

Suppose that we have a many-to-many mapping between Employees and Departments. An Employee can belong to many Departments, and a Department can contain many Employees. Both are managed with Sets. Assume Department->Employee is the main association, i.e. inverse="true" is defined in the Employee set in the Department mapping file.

From what I read above, it appears that this code used to work:

Code:
// Assume d is a Department, e is an Employee, initialized elsewhere.
d.getEmployees().remove( e );
e.getDepartments().remove( d );
session.save( d );
// The association in the join table between employee and department
// has been removed by this point, because of cascading


But that same code, in hibernate 3, will not work, as it will not remove the association between the two objects that is in the join table. Instead, we need to craft a query to delete it by hand. Something more along the lines of:

Code:
// Assume d is a Department, e is an Employee, initialized elsewhere.
d.getEmployees().remove( e );
e.getDepartments().remove( d );
session.save( d );
session.save( e );
// run an HQL query to delete the association here, as well


------
Is this really the case? Do I understand what was written above correctly?

If this is the case, why would we have to drop down to HQL to manage something that other than this case, is fully managed by Hibernate?
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 6:16 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, this is not the case. It works like before.


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