-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete in many-to-many
PostPosted: Mon Aug 02, 2004 12:06 am 
Newbie

Joined: Sun Aug 01, 2004 11:50 pm
Posts: 4
User.hbm.xml
<set name="roles" table="Role_User_Link" lazy="true" inverse="false" cascade="all" sort="unsorted">
<key column="user_id"/>
<many-to-many class="com.sungoal.cei.domain.Role" column="role_id" outer-join="auto"/>
</set>

Roles.hbm.xml

<set name="users" table="Role_User_Link" lazy="true" inverse="false" cascade="all" sort="unsorted">
<key column="role_id"/>
<many-to-many class="com.sungoal.cei.domain.User" column="user_id" outer-join="auto"/>
</set>

The table Role_User_Link is created. The insert of it is also OK. But how to delete one relationship???

Here is my code:
Code:
UserDAO userDAO = new UserDAO();
User user = userDAO.load(new Long(1);
Collection roles = user.getRoles();      //Here get 3 roles for example
Role roleOne = getOneRoleFromRoles(roles);   //Get one role from it
roles.remove(roleOne);            //Remove it
session.save(user);            //Now only two role in roles


But it doesn't work. The data in Role_User_Link is still 3 record. None is delete. If I set cascade = "all-delete-orphan", the data in roles table will be deleted, which is not what I expected.

Can anybody tell me what to do? Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 6:34 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
try with inverse="true" in Roles.hbm.xml:
Code:
<set name="users" table="Role_User_Link" lazy="true" inverse="true" cascade="all" sort="unsorted">
<key column="role_id"/>
<many-to-many class="com.sungoal.cei.domain.User" column="user_id" outer-join="auto"/>
</set>

Inside explanation of inverse=true http://www.hibernate.org/155.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 11:06 pm 
Newbie

Joined: Sun Aug 01, 2004 11:50 pm
Posts: 4
hi, thank u

In fact, I mistype something first,

In my former xml, I use inverse="true" in User.hbm.xml, while inverse="false" in Role.hbm.xml, in fact, they should be exchanged.

Now I understand why. Thanks a lot


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