views:

673

answers:

0

Hi,

Using NHibernate 1.2.0.

I have a parent-child relationship with a polymorphic parent class. The child has a many-to-one "Parent" property referencing the base parent class.

In HQL, starting from the child class, I need to access a property of one of the derived parent types.

Something like:

select parentA.SomeProperty from Child c left join c.DerivedParentA parentA

The mapping is similar to this:

<class name="Child" table="Children">
  <many-to-one name="Parent" column="ParentId" class="Parent" not-null="true"/>
</class>

<class name="Parent" table="Parents">
  ...
  <discriminator column="ColA" type="String"/>
</class>

<subclass name="DerivedParentA" table="Parents" extends="Parent" discriminator-value="A">
  <property name="Foo" type="String"/>
  ...
</subclass>

<subclass name="DerivedParentB" table="Parents" extends="Parent" discriminator-value="B">
  ...
</subclass>

How do I add a "DerivedParentA" property to the Child class mapping?

TIA!

Roy

related questions