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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:30:03+00:00 2026-06-12T21:30:03+00:00

I’m working with a legacy database and have following mappings: PersonBase: <?xml version=1.0 encoding=utf-8

  • 0

I’m working with a legacy database and have following mappings:

PersonBase:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Example.Person" assembly="Example">
  <class name="PersonBase" table="WN" lazy="false">
    <id name="Id" column="`id`" type="int" >
      <generator class="identity"/>
    </id>
    <property name="Name" column="`NAAM`" type="string"  />
    <property name="FirstName" column="`VOORNAAM`" type="string"  />


    <many-to-one name="Section" class="CodeDescription" lazy="false"  not-found="ignore" fetch="join" outer-join="true">
      <formula>'96'</formula>
      <column name="SEKTIE" />
      <formula>'1'</formula>
    </many-to-one>

    <many-to-one name="Country" class="CodeDescription" lazy="false"  not-found="ignore" fetch="join" outer-join="true">
      <formula>'25'</formula>
      <column name="Per_countryCD" />
      <formula>'1'</formula>
    </many-to-one>
  </class>
</hibernate-mapping>

CodeDescription:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
         namespace="Example.Person"
         assembly="Example">
  <class name="CodeDescription" table="Code" lazy="false">
    <composite-id>
      <key-property name="Kind" column="`CD_SRT`" type="string"/>
      <key-property name="Code" column="`CD`" type="string"  />
      <key-property name="Language" column="`CD_TAAL`" type="string"  />
    </composite-id>

    <property name="Description" column="`OMSCHR`" type="string" />
    <property name="DescriptionShort" column="`OMSCHR_KORT`" type="string" />
    <property name="ExternalCode" column="`ExternalCode`" type="string" />
    <property name="ExternalCode2" column="`ExternalCode2`" type="string" />
  </class>
</hibernate-mapping>

But when I try to get my persons it generates 2 extra queries per row found for the CodeDescriptions.

Generated queries:

   SELECT
        this_."NAAM" as y0_,
        this_."id" as y1_,
        this_."VOORNAAM" as y2_,
        '96' as y3_,
        this_.SEKTIE as y4_,
        @p0 as y5_,
        '25' as y6_,
        this_.Per_countryCD as y7_,
        @p0 as y8_ 
    FROM
        WN this_ 
    ORDER BY
        y0_ asc limit @p2;
    @p0 = 1 [Type: Int32 (0)],
    @p2 = 20 [Type: Int32 (0)]
NHibernate.SQL: 2012-10-08 16:07:24,013 [39] DEBUG NHibernate.SQL [(null)] - 
    SELECT
        codedescri0_."CD_SRT" as CD1_33_0_,
        codedescri0_."CD" as CD2_33_0_,
        codedescri0_."CD_TAAL" as CD3_33_0_,
        codedescri0_."OMSCHR" as OMSCHR5_33_0_,
        codedescri0_."OMSCHR_KORT" as OMSCHR4_33_0_,
        codedescri0_."ExternalCode" as External6_33_0_,
        codedescri0_."ExternalCode2" as External7_33_0_ 
    FROM
        Code codedescri0_ 
    WHERE
        codedescri0_."CD_SRT"=@p0 
        and codedescri0_."CD"=@p1 
        and codedescri0_."CD_TAAL"=@p2;
    @p0 = '96' [Type: String (0)], @p1 = '115' [Type: String (0)], @p2 = '1' [Type: String (0)]
NHibernate.SQL: 2012-10-08 16:07:24,015 [39] DEBUG NHibernate.SQL [(null)] - 
    SELECT
        codedescri0_."CD_SRT" as CD1_33_0_,
        codedescri0_."CD" as CD2_33_0_,
        codedescri0_."CD_TAAL" as CD3_33_0_,
        codedescri0_."OMSCHR" as OMSCHR5_33_0_,
        codedescri0_."OMSCHR_KORT" as OMSCHR4_33_0_,
        codedescri0_."ExternalCode" as External6_33_0_,
        codedescri0_."ExternalCode2" as External7_33_0_ 
    FROM
        Code codedescri0_ 
    WHERE
        codedescri0_."CD_SRT"=@p0 
        and codedescri0_."CD"=@p1 
        and codedescri0_."CD_TAAL"=@p2;
    @p0 = '96' [Type: String (0)], @p1 = '115' [Type: String (0)], @p2 = '1' [Type: String (0)]
NHibernate.SQL: 2012-10-08 16:07:24,016 [39] DEBUG NHibernate.SQL [(null)] - 
    SELECT
        codedescri0_."CD_SRT" as CD1_33_0_,
        codedescri0_."CD" as CD2_33_0_,
        codedescri0_."CD_TAAL" as CD3_33_0_,
        codedescri0_."OMSCHR" as OMSCHR5_33_0_,
        codedescri0_."OMSCHR_KORT" as OMSCHR4_33_0_,
        codedescri0_."ExternalCode" as External6_33_0_,
        codedescri0_."ExternalCode2" as External7_33_0_ 
    FROM
        Code codedescri0_ 
    WHERE
        codedescri0_."CD_SRT"=@p0 
        and codedescri0_."CD"=@p1 
        and codedescri0_."CD_TAAL"=@p2;
    @p0 = '96' [Type: String (0)], @p1 = '115' [Type: String (0)], @p2 = '1' [Type: String (0)]

    And so on .... (for every row)

This is a huge performance hit, because if I fully map my person it will have 20 CodeDescriptions.

Edit – My composite ID class:

public class CodeDescription
    {        
        public string Code { get; set; }

        public string Description { get; set; }

        public string DescriptionShort { get; set; }

        public string ExternalCode { get; set; }

        public string ExternalCode2 { get; set; }

        public CodeDescriptionKind Kind { get; set; }

        public string Language { get; set; }


        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return Description;
        }

        public CodeDescription()
        {

        }

    }
  • 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-12T21:30:04+00:00Added an answer on June 12, 2026 at 9:30 pm

    can you double check that your euqals and gethashcode is correctly implemented on the class with the compositeid? It’s often a source of such weird things. Equals and GetHashcode should mimic the composite primary key equality

    • 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 view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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 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 using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.