Sergey,
THat doesn't work. I have the following.
(another explanation of this exact problem can be found in this thread:
http://forum.hibernate.org/viewtopic.php?t=941990 see the post by dtabuenc )
Code:
<set name="ElectronicAddresses" lazy="true" >
<key column="contactid"/>
<one-to-many class="Demo.ElectronicAddress"/>
</set>
I captured the query in SQL Server profiler and NHibernate passes the personid value as the contactid. It's missing the join through the Contact table.
Nhibernate needs to create a query like:
Code:
select <fields> from person a
join contact b on a.personid = b.personid
join ElectronicAddress c on b.contactid = c.contactid
where a.personid = ?
Make sense? Am i missing something?
edit: added mapping files
Code:
<class name="Parent" table="Parent" >
<id name="Id" column="ParentId" type="Int32">
<generator class="identity"/>
</id>
<property name="ActiveDate" column="FromDate" type="Date"/>
<set name="ElectronicAddresses" lazy="true" order-by="contactmechanismid" inverse="true">
<key column="contactmechanismid" />
<one-to-many class="Demo.ElectronicAddress, Demo"/>
</set>
<joined-subclass name="Person" table="Person" >
<key column="ParentId"/>
<property name="FirstName" type="String"/>
<property name="LastName" type="String"/>
</joined-subclass>
Code:
<class name="Contact" table="Contact" >
<id name="Id" column="ContactID" type="Int32">
<generator class="identity"/>
</id>
<property name="ActiveDate" column="FromDate" type="Date"/>
<joined-subclass name="ElectronicAddress" table="ElectronicAddress" >
<key column="ContactID"/>
<property name="AddressString" type="String"/>
</joined-subclass>
</class>