-->
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: many-to-many faulty delete optimization when filter in use
PostPosted: Fri May 27, 2005 10:39 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Hi,

I have a problem when deleting from a many-to-many associations in our object model when filters are on. I believe it is due to a faulty optimization or because filters are not applied when writing.

Here is the case:

I have 2 entities: Group and Role. Group has a many-to-many relationship with Role and Role has an attribute called domain.

On the Group mapping document, we have a filter set up on the <many-to-many> association to Role that discriminate based on its domain attribute:
Code:
<set name="assignedRoles" table="security_group_to_role" lazy="true" cascade="save-update" access="property">
   <key column="group_id"/>
   <many-to-many class="SecurityRoleImpl" column="role_id">
      <filter name="FilterSecurityObjectBasedOnDomainId" condition="domain=:domain"/>
   </many-to-many>
</set>


Here the sequence of events that causes my problem when trying to reassociate different roles to the Group:
I load a Group Object
I call Hibernate.initialize(group.getRoles()) to activate the collection
I remove all roles in the collection by calling the Collection.remove() method for each role.
I persist the Group.

The SQL that gets executed is: delete from security_group_to_role where groupId = ?

This makes no sense since there are other roles associated through this table, but they were just not loaded at first (and hence not deleted) because the filter was up.

If I do not delete all roles in the collection, hibernate executes many statement like: delete from security_group_to_role where groupId=? and roleId=?

Is this a bug? If no, what is the workaround?


Hibernate version:
3.0.3


The unit test:

Code:
public void testResettingRolesForGroupUnderADomainIdDoesNotImpactAssociationsUnderAnotherDomainId() {
        service.setSecurityDomain(service.findSecurityDomainById(new Long(654456)));
        SecurityGroup group = service.findSecurityGroupById(new Long(512454));
        Collection roles = service.getAssociatedRolesForGroup(group);
        assertTrue("Could not retrieve associated roles for a group when filtered by domain", roles.size() > 0);
        service.associateRolesToGroup(group,  new ArrayList());// assigning nothing...
        roles = service.getAssociatedRolesForGroup(group);
        assertEquals("There should be no more roles associated to this group",0, roles.size());
        service.setSecurityDomain(service.findSecurityDomainById(new Long(654457)));
        group = service.findSecurityGroupById(new Long(512454));
        roles = service.getAssociatedRolesForGroup(group);
        assertEquals("Roles for another domain were deleted...", 1, roles.size());
    }


Thanks in advance for your help :)

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 10:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
PLease enter an issue in JIRA.


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.