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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:55:25+00:00 2026-06-13T05:55:25+00:00

NHibernate has a system called Mapping by code that gives the developer the possibility

  • 0

NHibernate has a system called Mapping by code that gives the developer the possibility to map their database in code (as the name says). I am using NHibernate 3.3.1.

I have done this for two classes: “Gebruiker” and “Lijst”. They both have a list of eachother so this is a classic example of a many to many relation.

The mapping is as follows:

Gebruiker

        Set(l => l.Lijsten, map =>
            {
                map.Table("LijstGebruiker");
                map.Cascade(Cascade.All);
                map.Inverse(true);
                map.Key(k => k.Column("Gebruiker"));
            }, map => map.ManyToMany(p => p.Column("Lijst")));

Lijst

         Set(l => l.Gebruikers, map =>
             {
                 map.Table("LijstGebruiker");
                 map.Cascade(Cascade.All);
                 map.Key(k => k.Column("Lijst"));
             }, map => map.ManyToMany(p => p.Column("Gebruiker")));

As far as I know this should result in the table "LijstGebruiker" with the columns Gebruiker and Key.

Instead: NHibernate generates a table LijstGebruiker with three columns, one extra in the addition to the two expected ones: elt. Elt also refers to Lijst using a foreign key.

According to the websites I found on the internet about this this should not happen, yet it is. What am I doing wrong?

  • 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-13T05:55:26+00:00Added an answer on June 13, 2026 at 5:55 am

    Apparently, this is some kind of strange behavior that happened when column name equals class name. The mapping generated by your code is:

    Gebruiker

    <set name="Lijsten" table="LijstGebruiker" inverse="true" cascade="all">
       <key column="Gebruiker" />
       <many-to-many class="Lijst" />
    </set>
    

    Lijst

    <set name="Gebruikers" table="LijstGebruiker" cascade="all">
      <key column="Lijst" />
      <many-to-many class="Gebruiker" />
    </set>
    

    So, there is no column in many-to-many element. It could be a bug in NHibernate.

    If you rename columns to Gebruiker_id and Lijst_id then everything works fine.

    Another solution is to specify column name using multiple column definition method:

    Gebruiker

    Set(l => l.Lijsten, map =>
    {
        map.Table("LijstGebruiker");
        map.Cascade(Cascade.All);
        map.Inverse(true);
        map.Key(k => k.Column("Gebruiker"));
    }, map => map.ManyToMany(p =>
    {
        p.Columns(x => x.Name("Lijst"));
    }));
    

    Lijst

    Set(l => l.Gebruikers, map =>
    {
        map.Table("LijstGebruiker");
        map.Cascade(Cascade.All);
        map.Key(k => k.Column("Lijst"));
    }, map => map.ManyToMany(p =>
    {
        p.Columns(x => x.Name("Gebruiker"));
    }));
    

    The mapping generated by the code is:

    <set name="Lijsten" table="LijstGebruiker" inverse="true" cascade="all">
      <key column="Gebruiker" />
      <many-to-many class="Lijst">
        <column name="Lijst" />
      </many-to-many>
    </set>
    
    <set name="Gebruikers" table="LijstGebruiker" cascade="all">
      <key column="Lijst" />
      <many-to-many class="Gebruiker">
        <column name="Gebruiker" />
      </many-to-many>
    </set>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does nHibernate create code that has all the details of the column? I know
I am using Fluent NHibernate on a project that has an Oracle 10g database.
I'm using Fluent NHibernate to map a a class that has a collection of
In NHibernate you can map generics like this <class name=Units.Parameter`1[System.Int32], Units table=parameter_int > </class>
When I map an entity that has a property of type System.Type, I know
I'm new to NHibernate, and am trying to map a domain model that has
Take this following code from an example HR system. The user has the ability
I'm designing a C#/NHibernate website that features a private messaging system. I would like
I'm working with a legacy system that I'm experimenting with adding NHibernate to. I
We currently have a system where each client gets their own database when they

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.