List of subclass picking up all classes in table-per-class-hierarchy

17 views
Skip to first unread message

Trinition

unread,
Mar 22, 2012, 11:54:44 AM3/22/12
to nhu...@googlegroups.com
We have a class, SpecialContainer (itself a subclass of Container), that has a list of contents of type TypeThreeContent:

class SpecialContainer {
  private IList<TypeThreeContent> _contents = new List< TypeThreeContent >();
}

TypeThreeContent is just a subclass of BaseContent, both of which have some uninteresting properties I've omitted for simplicitly.  Here's the mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" discriminator-value="0" name="AbstractBaseContent" table="tblContent">
    <id access="field" name="_id" type="System.Int32" unsaved-value="0">
      <column name="ContentID" />
      <generator class="identity" />
    </id>
    <discriminator type="Int32">
      <column name="FormsType" />
    </discriminator>
    <subclass name="TypeOneContent" discriminator-value="1">
    </subclass>
    <subclass name="TypeTwoContent" discriminator-value="2">
    </subclass>
    <subclass name="TypeThreeContent" discriminator-value="3">
    </subclass>
  </class>

  <class xmlns="urn:nhibernate-mapping-2.2" discriminator-value="-1" name="BaseContainer" table="tblContainers">
  ...
  <subclass name="SpecialContainer" discriminator-value="1">
      <join table="tblSpecialContainers">
      ...
        <bag access="field" cascade="none" inverse="true" lazy="true" name="_contents">
          <key>
            <column name="ContainerId" />
          </key>
          <one-to-many class="TypeThreeContent" />
        </bag>
</join>
  </class>
</hibernate-mapping>

The problem I'm having is that rows with other discriminator values (i.e. 1 and 2) are getting picked up in NH's fetching of the list.  I used NHProf to verify that the SQL query is not specifying a discriminator in its criteria:

SELECT ...
FROM   dbo.tblContent content0_
WHERE  content0_.SpecialContainerId = 140 /* @p0 */

What's going on here?
Reply all
Reply to author
Forward
0 new messages