Hi,
Im using a many-to-many association to map Users to Roles. I'm trying to remove an association, lets say, unjoin a user from a role. Basically im expecting this to just remove a record from the association table.
I have code like this:
Code:
Role role1 = new Role( "role1" );
Role role2 = new Role( "role2" );
Save(role1); // Call session.Save()
Save(role1); // Call session.Save()
User user = new User( "user1" );
user.Roles.Add( role1 );
role1.Users.Add( user );
user.Roles.Add( role2 );
role2.Users.Add( user );
Save( user );
// All is good up to this point
user.Roles.Remove( role1 );
role1.Users.Remove( user );
Update( user ); // Call session.Update()
On the call to session.Update() I get a HibernateException with the message : another object with the same id was already associated with the session
I don't know if im missing something, doing something wrong or is this a known issue. Please help. Thanks!
Here's part of my xml mapping file
Code:
<subclass
name="Project.Security.Roles.Role, Project.Security"
discriminator-value="Role">
<bag
name="Users"
table="UserRole"
lazy="false"
cascade="save-update"
inverse="true" >
<key column="RoleID" />
<many-to-many
column="UserID"
class="Project.Security.Roles.User, Project.Security" />
</bag>
</subclass>
<subclass
name="Project.Security.Roles.User, Project.Security"
discriminator-value="User" >
<bag
name="Roles"
table="UserRole"
lazy="false"
cascade="save-update" >
<key column="UserID" />
<many-to-many
column="RoleID"
class="Project.Security.Roles.Role, Project.Security" />
</bag>
</subclass>