Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate Issue: List of subclass picking up all classes in table-per-class-hierarchy
    primarykey
    data
    text
    <p>We have a class, SpecialContainer (itself a subclass of Container), that has a list of contents of type TypeThreeContent:</p> <pre><code>class SpecialContainer { private IList&lt;TypeThreeContent&gt; _contents = new List&lt; TypeThreeContent &gt;(); } </code></pre> <p>TypeThreeContent is just a subclass of BaseContent, both of which have some uninteresting properties I've omitted for simplicitly. Here's the mapping:</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-​2.2"&gt; &lt;class xmlns="urn:nhibernate-mapping-​2.2" discriminator-value="0" name="AbstractBaseContent" table="tblContent"&gt; &lt;id access="field" name="_id" type="System.Int32" unsaved-value="0"&gt; &lt;column name="ContentID" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;discriminator type="Int32"&gt; &lt;column name="FormsType" /&gt; &lt;/discriminator&gt; &lt;subclass name="TypeOneContent" discriminator-value="1"&gt; &lt;/subclass&gt; &lt;subclass name="TypeTwoContent" discriminator-value="2"&gt; &lt;/subclass&gt; &lt;subclass name="TypeThreeContent" discriminator-value="3"&gt; &lt;/subclass&gt; &lt;/class&gt; &lt;class xmlns="urn:nhibernate-mapping-​2.2" discriminator-value="-1" name="BaseContainer" table="tblContainers"&gt; ... &lt;subclass name="SpecialContainer" discriminator-value="1"&gt; &lt;join table="tblSpecialContainers"&gt; ... &lt;bag access="field" cascade="none" inverse="true" lazy="true" name="_contents"&gt; &lt;key&gt; &lt;column name="ContainerId" /&gt; &lt;/key&gt; &lt;one-to-many class="TypeThreeContent" /&gt; &lt;/bag&gt; &lt;/join&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>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:</p> <p>SELECT ... FROM dbo.tblContent content0_ WHERE content0_.SpecialContainerId = 140 /* @p0 */</p> <p>What's going on here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload