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 8808443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:37:28+00:00 2026-06-14T02:37:28+00:00

I have an entity class that represents a person and an enum that represents

  • 0

I have an entity class that represents a person and an enum that represents permissions that a person has. I am trying to map this relationship to a database using nhibernate mapping by code without any success.

The code looks like this:

public enum Permissions
{
  None = 1,
  CanUpdate = 2,
  CanInsert = 3,
  CanDelete = 4
}

public class Person
{
   private ICollection<Permissions> permissions;

   public Person()
   {
      this.permissions = new Collection<Permissions>();
   }

   public virtual ICollection<Permissions> Permissions
   {
      get
      {
         return this.permissions;
      }
   }
}

public class PersonMap : ClassMapping<Person>
{
   public PersonMap()
   {
      this.Set(
        x => x.Permissions,
        m =>
          {
             m.Access(Accessor.Field);
             m.Key(k => k.Column("PersonId"));
             m.Table("PersonHasPermission");
          },
        map => map.Element(
        p =>
          {
             p.Column("PermissionId");
             p.Type<NHibernate.Type.EnumType<Permissions>>();
          }));
    }
}

The database tables look like this:

Person
-----------------------
PersonId (PK, uniqueidentifier, not null)
Name (nvarchar(max), not null)


PersonHasPermission
-----------------------
PersonId (PK, FK, uniqueidentifier, not null)
PermissionId (PK, FK, int, not null)

So, with this configuration I do not get any exceptions but whenever I try to fetch the permissions for a person the collection is always empty even though there is data in the database.

I’m hoping that the code above is explains what I am trying to achieve, but do let know if further clarity is required.

Any help with this would be much appreciated. Thanks in advance.

  • 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-06-14T02:37:29+00:00Added an answer on June 14, 2026 at 2:37 am

    I am using XML configuration, where I can map even protected or private members. So, surprising for me is that you are not receiving any Exception. Because your Collection does not have any setter (public nor protected). I would expect something like this:
    NHibernate.PropertyNotFoundException: {“Could not find a setter for property ‘Permissions’ in class ‘Person'”}
    But maybe fluent is able to translate your mapping from Property to field.

    I tried to test your code with a public setter or field (both shown below) and it worked. there is my snippet of xml mapping:

    <!-- public or protected setter -->
    <bag name="Permissions" inverse="false" lazy="true" table="PresonHasPermission" cascade="all">
       <key column="PersonId" />          
       <element type="Permissions" column="PermissionId" />
    </bag>
    
    <!-- accessing the field -->
    <bag name="permissions" inverse="false" lazy="true" table="PresonHasPermission" cascade="all"
       access="field" >
       <key column="PersonId" />          
       <element type="Permissions" column="PermissionId" />
    </bag>
    

    (Leaving your class definition unchanged when mapping to field)

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

Sidebar

Related Questions

I have an entity class that has 10 fields. I am using MS Validation
In my business model I have Entity class (IPoint interface ) that has a
I have a class that provide the CRUD operation for an entity.Im using the
I have settings that I store in my database. There is an entity class
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
If I have this entity: @Entity class Pet { @Id long id; public enum
I have a domain class called Flight that represents a flight that has been
I have an entity class that represents an object brought over from MySQL. One
I have an Entity/JSF Managed Bean Ticket that represents a helpdesk ticket. It has
In the project I'm working on now, we have base Entity class that looks

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.