title: NHibernate One-To-Many with Joined Subclass
body: <p>Never asked a question here before, I'll try to lay this out as succinctly as possible.  </p>
  
  <p>I've got a Recipe class, that contains lists of three different types of Ingredient Uses.  These classes all inherit from the base, IngredientUse.  So the mapping looks like this:</p>
  
  <pre><code>  &lt;class name="IngredientUse" table="IngredientUses"&gt;
      &lt;id name="Id" type="Int64" column="Id"&gt;
        &lt;generator class="native"/&gt;
      &lt;/id&gt;
      &lt;!--some other properties--&gt;
      &lt;property name="RecipeId" column="RecipeId"/&gt;
      &lt;joined-subclass name="AdditionUse" table="AdditionUses"&gt;
        &lt;key column="Id" foreign-key="FK_AdditionUses_IngredientUses"/&gt;
        &lt;many-to-one name="AdditionUsed" column="AdditionUsed" class="Addition" foreign-key="FK_AdditionUses_Additions"/&gt;
      &lt;/joined-subclass&gt;
    &lt;/class&gt;
  </code></pre>
  
  <p>The one causing problems here is the RecipeId.  From the recipe, I have three separate lists of uses for different ingredient types, defined like so:</p>
  
  <pre><code>&lt;bag name="AdditionsUsed" cascade="all" lazy="false"&gt;
    &lt;key column="RecipeId"/&gt;
    &lt;one-to-many class="AdditionUse"/&gt;
  &lt;/bag&gt;
  </code></pre>
  
  <p>Now, I'm running into problems trying to load these lists.  It has something to do with the inheritance.  When I look at the SQL Generated, I see this:</p>
  
  <pre><code>SELECT additionsused0_.RecipeId as RecipeId1_
  --other columns not really important
  FROM AdditionUses additionsused0_ 
  inner join IngredientUses additionsused0_1_ 
  on additionsused0_.Id=additionsused0_1_.Id 
  WHERE additionsused0_.RecipeId=@p0; @p0 = '11'
  </code></pre>
  
  <p>Notice that its' looking for the RecipeId in the subclass' table, and not the base table where the column is actually contained.  I know I could just define a separate table for each ingredient type, but that will cause me problems because there are some situations (ie pricing) where I don't need the additional columns in the subclass table, and would like to be able to load all the ingredients into the same list at once.</p>
  
  <p>I'm certain I must be missing something here, figured someone more familiar with NHibernate on this site might recognize it right off the bat.  </p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>edit:</strong> in case I wasn't clear about what I'm trying to do, this diagram might help (excuse my shoddy UML, hope it doesn't muddy the waters).  There is also an Ingredient base class, and the same subtypes off of that.</p>
  
  <p><img src="https://farm4.static.flickr.com/3565/3319584915_ac1a3ce005.jpg?v=0" alt="diagram"></p>