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: removing link in many-to-many relations
PostPosted: Sat Jan 15, 2005 3:09 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Hibernate version:2.1.7

Mapping documents:
<class name="User" table="USER">
<id name="id" type="java.lang.Long" column="USER_ID" unsaved-value="null">
<generator class="native" />
</id>
<property name="name" type="string" length="50"
column="USER_NAME" />
<set name="rolesSet" table="USER_ROLE_MAP"
access="field" >
<key column="USER_ID" />
<many-to-many column="ROLE_ID" class="Role" />
</set>
</class>


<class name="Role" table="ROLE">
<id name="id" type="java.lang.Long" column="ROLE_ID" unsaved-value="null">
<generator class="increment" />
</id>
<property name="name" type="string" length="50" column="ROLE_NAME" />
<set name="privilegesSet" table="ROLE_PRIV_MAP"
access="field">
<key column="ROLE_ID" />
<many-to-many column="PRIVILEGE_ID" class="Privilege" />
</set>
</class>



Code between sessionFactory.openSession() and session.close():
getHibernateTemplate().saveOrUpdate(dataSource);


Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9.0


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



Code:
role = dao.getRole(roleId);
    user = dao.getIser(userId);
    user.removeRole(role);
    dao.updateUser(user);


I expected that above code would delete the link between a user and a role . But hibernate is not deleting it..(it is not doing anything) I am getting user and role objects from different sessions. So the Set in the user object may not contain the exact role object. Is that the reason? But i tried to override the equals and hashcode methods in the Role class such that two roles are equal if their ids are equal. but that override method in not even getting called...

This is my removeRole method in the User class

Code:
    public void removeRole(Role role) {
        rolesSet.remove(role);
    }


plz help!!

Thanks,
SSSS.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
very likely an equals/hashcode issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 9:01 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Does contains method in Set call equals method???
Because with the overridden equals method ArrayList.contains(myObject) returns true, but Set.contains(myObject) returns false!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 10:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sun provides the sources of this part of the JVM :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 7:31 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Can you give some clue how to do it?
Do I need to override euqals/hashCode methods?
or is there any other way?

Thanks in advance,
SSSS


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.