Remove from one side of the many to many in Nhibernate -


i have these 2 objects in nhibernate forming many many relationship:

user:

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"                    assembly="providers" namespace="providers.objects">    <class name="user" table="users">      <id name="userid" type="int">       <generator class="native" />     </id>      <many-to-one name="application" column="applicationid" cascade="none" />          <property name="username" type="string" />     <property name="loweredusername" type="string" />     <property name="mobilealias" type="string" />     <property name="isanonymous" type="bool" />     <property name="lastactivitydate" type="datetime" />      <bag name="roles" table="usersinroles" lazy="true" cascade="none" >       <key column="userid"></key>       <many-to-many class="role" column="roleid"></many-to-many>     </bag>    </class>  </hibernate-mapping> 

and role:

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"                    assembly="providers" namespace="providers.objects">    <class name="role" table="roles">      <id name="roleid" type="int">       <generator class="native" />     </id>      <many-to-one name="application" column="applicationid" class="application" cascade="none" />          <property name="rolename" type="string" />     <property name="loweredrolename" type="string" />     <property name="description" type="string" />      <bag name="users" table="usersinroles" lazy="true" inverse="true" cascade="none" >       <key column="roleid"></key>       <many-to-many class="user" column="userid"></many-to-many>     </bag>    </class>  </hibernate-mapping> 

let's role backupoperator has users in it. if try remove 1 of users role instance, like:

var backupoperator = getrolebyname(session, app.applicationid, "backupoperator"); backupoperator.users.removeat(0); session.update(backupoperator); transaction.commit(); 

it doesn't work :( association remains unchanged in database. when try opposite (remove role user object , updating user object), works. because of inverse attribute in nhibernate mapping?

how accomplish trying do? (remove user role, updating role , having persisted)?

thanks

when write inverse="true" telling nhibernate other side maintains relationship.

therefore, have remove role user's roles collection if want change persisted.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -