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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:18:14+00:00 2026-05-28T02:18:14+00:00

I’ve been struggling with this for a while see my previous question How to

  • 0

I’ve been struggling with this for a while see my previous question How to configure nHibernate for many-many mapping?

I have recreated my project from scratch in an attempt to solve it. I have two classes Broker and Instrument and I have a property unique to a Broker and an Instrument called MinIncrement that I need to store in my many-many mapping table in the database. I created a third class called BrokerInstrument to model this extra information. Here is the code for my classes:

public abstract class Entity
{
    public virtual int Version {get; private set;}
}

public class Broker : Entity
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual bool IsDefault { get; set; }
    public virtual bool IsActive { get; set; }
    public virtual ISet<BrokerInstrument> BrokerInstruments { get; set; }
}

public class Instrument : Entity
{
    public virtual int Id { get;  set; }
    public virtual string Name { get;  set; }
    public virtual string Symbol {get;  set;}
    public virtual ISet<BrokerInstrument> BrokerInstruments { get; set; }

}

public class BrokerInstrument : Entity
{
    public virtual Broker Broker { get; set; }
    public virtual Instrument Instrument { get; set; }
    public virtual decimal MinIncrement { get; set; }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        var t = obj as BrokerInstrument;
        if (t == null)
            return false;

        if ((Instrument == t.Instrument) && (Broker == t.Broker))
            return true;

        return false;
    }

    public override int GetHashCode()
    {
        return (Broker.Name + "|" + Instrument.Symbol).GetHashCode();            
    }
}

My mapping files look like this:
Broker.hbm.xml

  <class name="MooDB.Domain.Broker,MooDB" table="brokers">
    <id name="Id" column="brokerId" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <version name="Version" column="version" type="integer" unsaved-value="0" />
    <property name="Name" column="`name`" type="String" length="50" not-null="true" />
    <property name="IsActive" column="isActive" type="bool" not-null="true" />
    <property name="IsDefault" column="isDefault" type="bool" not-null="true" />
  </class>

Instrument.hbm.xml

  <class name="MooDB.Domain.Instrument,MooDB"  table="instruments">
    <id name="Id" column="instrumentId" type="Int32" unsaved-value="0">
      <generator class="native"></generator>
    </id>
    <version name="Version" column="version" type="integer" unsaved-value="0"/>
    <property name="Symbol" column="symbol" type="string" length="10" not-null="false"/>
    <property name="Name" column="`name`" type="string" length="30" not-null="false"/>
  </class>

And the mapping file I’m struggling with:
BrokerInstrument.hbm.xml

  <class name="MooDB.Domain.BrokerInstrument,MooDB"  table="brokerInstruments">
    <composite-id name="BrokerInstrumentIdentifier" class="BrokerInstrument" >
      <key-many-to-one class="Broker" column="brokerId" name="Id" />
      <key-many-to-one class="Instrument" column="instrumentId" name="Id" />
    </composite-id>
    <property name="MinIncrement" column="minIncrement" type="decimal" not-null="true" />
  </class>

I’m pretty sure the elements enclosed within composite-id tags are wrong. Do you know what should go in there? Also, does my class design look right to support this model?

UPDATE 1

In response to Cole’s reply. I have made the change suggested and I now get this error:

Test ‘Test.Test.CanAddBrokerInstrument’ failed: TestFixtureSetUp
failed in Test

TestFixture failed: NHibernate.PropertyNotFoundException : Could not
find a getter for property ‘BrokerInstrumentIdentifier’ in class
‘MooDB.Domain.BrokerInstrument’

  • 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-28T02:18:15+00:00Added an answer on May 28, 2026 at 2:18 am

    this isn’t really an M:N relationship. it’s a M:1 & 1:N relationships between 3 entities. From simplicity of modeling and queries I would assign an Id to BrokerInstrument and remove the need for a composite key all together.

    anytime you can avoid composite you should. this type of mapping is for legacy databases.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.