Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:03:41+00:00 2026-05-17T15:03:41+00:00

I have these 2 objects in NHibernate forming a many to many relationship: User:

  • 0

I have these 2 objects in NHibernate forming a many to 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 say the role backupoperator has some users in it. If I try to remove one of the users from the role instance, like:

var backupoperator = GetRoleByName(session, app.ApplicationId, "backupoperator");
backupoperator.Users.RemoveAt(0);
session.Update(backupoperator);
transaction.Commit();

It doesn’t work 🙁 The association remains unchanged in the database. When I try the opposite (remove a role from a user object and updating the user object), it works.
Is it because of the inverse attribute in the NHibernate mapping?

How to accomplish what I am trying to do? (remove a user from a role, updating the role and having that persisted)?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:03:42+00:00Added an answer on May 17, 2026 at 3:03 pm

    When you write inverse="true" you are telling NHibernate that the other side maintains the relationship.

    Therefore, you have to remove the Role from the User’s Roles collection if you want your change persisted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that has many assocations to other objects. All of these
I have these objects: public class Class { public Guid Id {get;set;} public string
Suppose I have these domain objects: DataPoint ========= public int Id {get;set;} public int
I have a list of custom objects. These objects have 2 datetime properties on
I have an array of pointers to Objective-C objects. These objects have a sort
I have an array made of unlimited number of objects. These objects have the
I have these code in my views.py: array = [] p = Person.objects.filter(client=1,status='Complete').values('name', 'age',
I have a hashmap containing objects created via a constructor. These objects are in
If I have a bunch of objects, and within these objects is the string
I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext . These objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.