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.