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

  • Home
  • SEARCH
  • 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 3612650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:01:39+00:00 2026-05-18T22:01:39+00:00

I have a Nhibernate mapping file for a simple user/role mapping. Here are the

  • 0

I have a Nhibernate mapping file for a simple user/role mapping.

Here are the mapping files:

Users.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Sample.Persistence" namespace="Sample.Persistence.Model">
    <class name="User" table="Users">
        <id name="UserKey">
            <generator class="identity"/>
        </id>

        <property name="UserName" column="UserName" type="String" />
        <property name="Password" column="Password" type="Byte[]" />

        <property name="FirstName" column="FirstName" type="String" />
        <property name="LastName" column="LastName" type="String" />
        <property name="Email" column="Email" type="String" />

        <property name="Active" column="Active" type="Boolean" />
        <property name="Locked" column="Locked" type="Boolean" />

        <property name="LoginFailures" column="LoginFailures" type="int" />
        <property name="LockoutDate" column="LockoutDate" type="DateTime" generated="insert" />

        <property name="Expired" column="Expired" type="Boolean" generated="insert"/>

        <set name="Roles" table="UsersRolesBridge"   lazy="false">
            <key column="UserKey" />
            <many-to-many class="Role"
            not-found="exception"
            column="RoleKey" />
        </set>

    </class>
</hibernate-mapping>

Role.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Sample.Persistence" namespace="Sample.Persistence.Model">
    <class name="Role" table="Roles">
        <id name="RoleKey">
            <generator class="identity"/>
        </id>
        <property name="Name" column="Name" type="String" />

        <set name="Users" inverse="true" table="UsersRolesBridge" lazy="false" >
            <key column="RoleKey" />
            <many-to-many class="User" column="UserKey" />
        </set>
    </class>
</hibernate-mapping>

I am able to retrieve roles for each user via NHibernate but when I go to save a new object, the roles are not saved in the Bridge table.

The user is created and insert with no issues. I’ve checked that the Role collection, a field on the user, is being populated with the proper rolekey before the Session.Save() is called.

There is no exception thrown as well.

UPDATE:

After adding a cascade, there was still no actual insert taking place to the M-2-M table.

The logs from Nhibernate showed the following:

12/22/2010 23:18:11.684 [11] INFO  NHibernate.Engine.Cascade 
Message: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: Sample.Persistence.Model.User
Exception: 

12/22/2010 23:18:11.686 [11] INFO  NHibernate.Engine.Cascade 
Message: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: Sample.Persistence.Model.User
Exception: 

12/22/2010 23:18:11.789 [11] INFO  NHibernate.Engine.Cascade 
Message: processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: Sample.Persistence.Model.User
Exception: 

12/22/2010 23:18:11.792 [11] INFO  NHibernate.Engine.Cascade 
Message: cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: Sample.Persistence.Model.User.Roles
Exception: 

12/22/2010 23:18:11.814 [11] INFO  NHibernate.Engine.Cascade 
Message: done cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: Sample.Persistence.Model.User.Roles
Exception: 

12/22/2010 23:18:11.814 [11] INFO  NHibernate.Engine.Cascade 
Message: done processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: Sample.Persistence.Model.User
  • 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-18T22:01:39+00:00Added an answer on May 18, 2026 at 10:01 pm

    You haven’t specified a cascade on the relationship. By default, inserts, updates, and deletes are not cascaded. More information here:

    http://ayende.com/Blog/archive/2006/12/02/nhibernatecascadesthedifferentbetweenallalldeleteorphansandsaveupdate.aspx

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

Sidebar

Related Questions

Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
NHibernate is driving me 'Nuts'!!! I have the following mapping. Which returns this error
I have what I think should be a fairly simple mapping issue, but not
I have a hibernate mapping as follows: <hibernate-mapping> <class name=kochman.elie.data.types.InvoiceTVO table=INVOICE> <id name=id column=ID>
I have the following Hibernate Mapping, which has to be mapped using the Table
I have an NHibernate session. In this session, I am performing exactly 1 operation,
I have an NHibernate Dao..lets call it MyClassDao for want of a better name.
Please if you have used NHibernate and Entity Frameworks, please contrast your experiences.
Ok, so I have an nHibernate ICriteria that returns an object. I want to
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly

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.