Never asked a question here before, I’ll try to lay this out as succinctly as possible.
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:
<class name='IngredientUse' table='IngredientUses'> <id name='Id' type='Int64' column='Id'> <generator class='native'/> </id> <!--some other properties--> <property name='RecipeId' column='RecipeId'/> <joined-subclass name='AdditionUse' table='AdditionUses'> <key column='Id' foreign-key='FK_AdditionUses_IngredientUses'/> <many-to-one name='AdditionUsed' column='AdditionUsed' class='Addition' foreign-key='FK_AdditionUses_Additions'/> </joined-subclass> </class>
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:
<bag name='AdditionsUsed' cascade='all' lazy='false'> <key column='RecipeId'/> <one-to-many class='AdditionUse'/> </bag>
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:
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'
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.
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.
Thanks in advance.
edit: 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.

That’s the expected behavior, the key tag is the name of the column in the ‘many’ side that references to the ‘one’…
Create the tables in a paper, and you’ll see that if you want that your ingredient has many additions, you will need add a column in the additions table.
By the way, never map your ids directly, map the entity instead using a many-to-one