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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:21:43+00:00 2026-05-23T20:21:43+00:00

I have an NHibernate problem with lists, which are mapped as subclasses of an

  • 0

I have an NHibernate problem with lists, which are mapped as subclasses of an abstract class.

First here is the mapping for the abstract class:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   auto-import="false"
                   assembly="Magma.Core"
                   namespace="Magma.Core.Business">
    <class name="SyndicatePart" table="biz_syndicatepart" abstract="true" lazy="false">
        <id name="Id" column="id">
            <generator class="guid.comb" />
        </id>
        <discriminator column="parttype" not-null="true" />

        <property name="Identifier" column="name" not-null="true" />
        <property name="Share" column="share" not-null="true" />
        <property name="CadasterNumber" column="cadaster_number" not-null="true" />

        <many-to-one name="Account" column="accountid" lazy="proxy" cascade="all" />
        <many-to-one name="Syndicate" column="syndicateid" lazy="proxy" cascade="all" />

        <subclass name="Condo" discriminator-value="condo" lazy="false">
            <property name="OwnerType" column="ownertype" />

                <many-to-one name="Building" column="buildingid" />
            <many-to-one name="Address" column="addressid" />

            <bag name="Tenants" access="field.camelcase-underscore" table="biz_tenant" inverse="true" cascade="all-delete-orphan">
                <key column="syndicatepartid" />
                <one-to-many class="Tenant" />
            </bag>
        </subclass>

        <subclass name="Parking" discriminator-value="park" lazy="false" />
        <subclass name="Locker" discriminator-value="lock" lazy="false" />
    </class>
</hibernate-mapping>

Notice the subclasses “Condo”, “Parking” and “Locker” (in my case, only Condo has additional properties). And this is the mapping of the object using lists of these subclasses:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Magma.Core"
                   namespace="Magma.Core.Business">
    <class name="Syndicate" table="biz_syndicate" abstract="true" lazy="false">
        <id name="Id" column="id">
            <generator class="guid.comb" />
        </id>
        <discriminator column="orientation" not-null="true" />

        <property name="Name" column="name" not-null="true" />

        <many-to-one name="Manager" column="managerid" cascade="all-delete-orphan" />

        <bag name="Buildings" table="biz_building" inverse="true" cascade="all-delete-orphan">
            <key column="syndicateid" />
            <one-to-many class="Building" />
        </bag>

        <bag name="Parkings" table="biz_syndicatepart" inverse="true" cascade="all-delete-orphan">
            <key column="syndicateid" />
            <one-to-many class="Parking" />
        </bag>

        <bag name="Lockers" table="biz_syndicatepart" inverse="true" cascade="all-delete-orphan">
            <key column="syndicateid" />
            <one-to-many class="Locker" />
            </bag>

        <subclass name="VerticalSyndicate" discriminator-value="vertical" lazy="false" />
        <subclass name="HorizontalSyndicate" discriminator-value="horizontal" lazy="false" />
    </class>
</hibernate-mapping>

Each of the lists is mapped as a bag pointing to the same table but of different class depending on the list (Condo, Parking and Locker).

Now to the problem. The problem is that when I try to access any of those lists, NHibernate fetches all of the rows in the biz_syndicatepart table and casting it to the proper class depending on the list. So let’s say I have 3 rows in the table, if I access the Parkings list, I’ll have 3 parkings. If I access the Lockers list, I’ll have 3 lockers! Here is the SQL generated for the parkings list:

SELECT parkings0_.syndicateid     as syndicat7_1_,
       parkings0_.id              as id1_,
       parkings0_.id              as id39_0_,
       parkings0_.name            as name39_0_,
       parkings0_.share           as share39_0_,
       parkings0_.cadaster_number as cadaster5_39_0_,
       parkings0_.accountid       as accountid39_0_,
       parkings0_.syndicateid     as syndicat7_39_0_
FROM   biz_syndicatepart parkings0_
WHERE  parkings0_.syndicateid = '2310fcdf-8ab3-48dd-9a75-9f1e00f6f4fd' /* @p0 */

First thing, notice the double parkings0_.id. Is this normal? Same thing for the parkings0_.syndicateid (first and last row of the select statement). This I really don’t understand.

Also, Notice that no discriminating WHERE clause is inserted to specify which type of list I want. I would assume that if I would access the Parkings list I would see a WHERE [discriminator-column] = [discriminator-value], in my case WHERE parttype = 'park' but it’s not in the statement so this is why every row gets returned.

I read that this might be a bug in NHibernate (I’m currently using version 3.1 GA) but reading the description of the bug it seems that it occurs when the key of the list is in the subclass table when using the table per subclass strategy (joined-subclass) so I don’t think it applies to my situation.

Can someone help me with this?! Do I have a problem with my mapping files? Why the double _id in the SELECT and why no discriminator WHERE clause?

  • 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-23T20:21:45+00:00Added an answer on May 23, 2026 at 8:21 pm

    The simple workaround is to add a where clause to your collection mapping. E.g.

        <bag name="Parkings" table="biz_syndicatepart" inverse="true" cascade="all-delete-orphan" where="parttype='park'">
            <key column="syndicateid" />
            <one-to-many class="Parking" />
        </bag>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that is mapped to a table using NHibernate. The problem
I have a problem with nhibernate mapping. I use the nhibernate 3.2 mapping by
I have a problem with class which should: issue couple invoices, shows/update progress bar
I have a rather complex mapping for some of my class objects for NHibernate.
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have a problem with: NHibernate.Cfg.Configuration.SetProperties() Not accepting the IDictionary: NHibernateConfigHandler I get the
I have a problem using Linq to NHibernate to load an object and eagerly
Using MVC3 with NHibernate, I am having a problem with dropdowns. I have a
I query my NHibernate datasources using a Linq Expression. The problem I have with
I have a problem with hibernate and criterias. I have two Classes: public class

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.