title: Nhibernate subclass mapping problem
body: <p>I am using nhibernate subclass mapping to handle descriptions of objects of the system. Basically idea is to have a description class and make polymorphic associations by having sub classes specific to the object. My code inserts the description data correctly to the Database; that means the ownerid and ownertype columns are created correctly when I insert data.</p>
  
  <p>But nhibernate is not using the OwnerType column for querying descriptions of Foo when I load Foo object using nhibernate.load() - It just queries the descriptions table using the ownerId column only which creates conflict since there can be other rows in the table with the same id but associated to a different ownertype.</p>
  
  <p>Can you helop me find why it does not include ownerType for descriptions on the load query and how can I fix this? Thanks!</p>
  
  <pre><code>public class Product : EntityBase
  {
      public virtual string Name { get; set; }
      public virtual IList&lt;ProductDescription&gt; Descriptions { get; set; }
  }
  
  public class ProductDescription : Description
  {
      public virtual Product Product { get; set; }
  }
  
  public class Description : EntityBase
  {
      public virtual string Name { get; set; }
      public virtual string ShortDescription { get; set; }
      public virtual string LongDescription { get; set; }
  }
  
  
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test.Domain" assembly="Test.Domain"&gt;
      &lt;class name="Test.Domain.Product, Test.Domain" table="Products"&gt;
          &lt;id name="ID" column="ID" type="Int32" unsaved-value="0"&gt;
              &lt;generator class="native" /&gt;
          &lt;/id&gt;
  
          &lt;property name="Name" /&gt;
  
          &lt;bag name="Descriptions" inverse="true" cascade="all"&gt;
              &lt;key column="OwnerID" /&gt;
              &lt;one-to-many class="Test.Domain.ProductDescription, Test.Domain" /&gt;
          &lt;/bag&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test.Domain" assembly="Test.Domain"&gt;
  &lt;class name="Test.Domain.Description, Test.Domain" table="Descriptions" discriminator-value="0"&gt;
          &lt;id name="ID" column="ID" type="Int32" unsaved-value="0"&gt;
              &lt;generator class="native" /&gt;
          &lt;/id&gt;
  
          &lt;discriminator column="OwnerType" /&gt;
  
          &lt;property name="Name" /&gt;
          &lt;property name="ShortDescription" /&gt;
          &lt;property name="LongDescription" /&gt;
  
          &lt;subclass name="Test.Domain.ProductDescription, Test.Domain" discriminator-value="1"&gt;
              &lt;many-to-one name="Product" class="Test.Domain.Product, Test.Domain" column="OwnerID" not-null="true"&gt;&lt;/many-to-one&gt;
          &lt;/subclass&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>