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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:23:37+00:00 2026-05-17T19:23:37+00:00

I have a legacy database with 3 tables like this: (source: bilder-hochladen.net ) The

  • 0

I have a legacy database with 3 tables like this:
Painting of Tables
(source: bilder-hochladen.net)

The Items table contains all the Items in a Plan.
The Structure table defines the relation between the items.
A parent item is defined by company, year, planId and parentItem of table structure mapping to company, year, planId and id of table item.
A child item is defined by company, year, planId and childItem of table structure mapping to company, year, planId and id of table item.

I am searching for a way to do a n:m mapping in nhibernate using either hbm or fluent mappings.

I came up with:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Project.Model" assembly="Project" xmlns="urn:nhibernate-mapping-2.2">
  <class name="Item" lazy="true" table="`item`" schema="`dbo`">
    <composite-id>
        <key-property name="Company" column="`company`" />
        <key-property name="Year" column="`year`" />
        <key-property name="Planid" column="`planid`" />
        <key-property name="ItemId" column="`id`" />
    </composite-id>  
    <!-- Some other properties -->

    <set name="Parents" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`parentItem`" />
        </key>
        <many-to-many class="Item">        
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
    </set>

    <set name="Childs" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`childItem`" />
        </key>
        <many-to-many class="Item">        
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
    </set>

    <many-to-one name="Plan" class="Plan" not-null="true" fetch="select">
        <column name="`company`" />
        <column name="`planid`" />
    </many-to-one>
  </class>
</hibernate-mapping>

The error however is: Repeated column in mapping … – so I’m stuck. Any suggestions?

  • 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-17T19:23:38+00:00Added an answer on May 17, 2026 at 7:23 pm

    Well I managed to solve this one. The key was to use key-many-to-one (KeyReference in FluentNHibernate) and not to make n:m mapping (because it does not work!):

    <?xml version="1.0" encoding="utf-8"?>
    <hibernate-mapping namespace="Project.Model" assembly="Project" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Item" lazy="true" table="`item`" schema="`dbo`">
      <composite-id>
        <key-many-to-one name="Plan" class="Plan">
          <column name="Company" column="`company`" />
          <column name="Planid" column="`planid`" />
        </key-many-to-one>
        <key-property name="Year" column="`year`" />
        <key-property name="ItemId" column="`id`" />
      </composite-id>  
      <!-- Some other properties -->
    
      <set name="Parents" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`parentItem`" />
        </key>
        <many-to-many class="Item">        
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
      </set>
    
      <set name="Childs" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`childItem`" />
        </key>
        <many-to-many class="Item">        
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
      </set>
      </class>
    
      <class name="Structure" lazy="true" table="`item`" schema="`dbo`">
        <composite-id>
      <key-many-to-one name="Parent" class="Item">
        <column name="company" />
        <column name="year" />
        <column name="planid" />
        <column name="parentItem" />
      </key-many-to-one>
      <key-many-to-one name="Child" class="Item">
        <column name="company" />
        <column name="year" />
        <column name="planid" />
        <column name="childItem" />
      </key-many-to-one>
      <key-property name="StructureId" column="structureId" />
    </composite-id>      
    </class>
    
    </hibernate-mapping>
    

    This looks somewhat weird, esp. the part where company, year and planid are twice in the key of Structure. But It works…

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

Sidebar

Related Questions

I have this legacy database for which I'm building a custom viewer using Linq
I currently have a database that gets updated from a legacy application. I'd like
I have to connect to a legacy postgres database which has ENCODING = 'SQL_ASCII';
I am using NHibernate's SchemaExport to create my database schema. I have 1 legacy
I have a name in a database, lets say its DFectuoso and some legacy
I have legacy asp.net 1.1 website. It has a very poor VB layered achitecture.
I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
We have some legacy code that needs to identify in the Page_Load which event
I have a legacy VB6 application that was built using MSDE. As many client's

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.