The following hbm.xml contains a on-to-many mapping for a property called Descriptions.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="X.Core.Data.Model, X.Core.Data" table="model" lazy="false">
<id name="Name" column="`Name`" type="String">
<generator class="assigned" />
</id>
<property name="DescriptionResId" type="Guid" />
<bag name="Descriptions" table="ResourceStrings" lazy="false" >
<key column="ResourceId" foreign-key="DescriptionResId" />
<one-to-many class="X.Core.Data.ResourceString, X.Core.Data" />
</bag>
<bag name="Features" table="Model2Feature" lazy="false">
<key column="ModelName" />
<many-to-many class="X.Core.Data.Feature, X.Core.Data" column="FeatureName" />
</bag>
</class>
</hibernate-mapping>
As you can see, I have set 'DescriptionResId' as the foreign-key. When I run my getter-code I get an exception, though. I've noticed that the generated SQL is OK, except for the where clause parameter. The parameter is assigned the Name of the Model instance (the PK of the Model table) and not the DescriptionResId I asked NHibernate to use.
Looking at the NHibernate source made me suspect that the foreign-key attribute is ignored for one-to-many mappings...
Am I correct, or just missing the obvious?
Thanks,
G.