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 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 a table that contains the stock. It's legacy database and the stock
I have a legacy database with a field which contains some parentheses, like red(b).
In legacy database tables we have numbered columns like C1, C2, C3, C100 or
I'm using SQL Server 2008. I have a database table that looks like this
I am working with a legacy database schema that looks like this: product_table table
I have a legacy mysql database and there's this table which has a few
I have a legacy SQL schema which looks something like this: CREATE TABLE `User`
I have legacy database and tables that I would like to try to import
I have a table which has essentially boolean values in a legacy database. The
I have a legacy database set with NLS_LANG set to IW8ISO8859P8. This I cannot

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.