I'm mixing table mapping strategies to store a class hierarchy via NHibernate 2.1.2. I'm not using Fluent NHibernate.
I understand how to map a table-per-hierarchy -> table-per-subclass structure, but not the other way around, as the XML is invalid after adding the discriminator.
Here's the HBM extract:
<class name="Base1" table="Base1">
<id name="Id" column="Id" type="int" />
<property name="Name" type="string" not-null="true" />
<property name="Description" type="string" not-null="false" />
<joined-subclass name="Base2" table="Base2">
<key column="BaseId" />
<set name="Children">
<key column="BaseId" />
<one-to-many class="Base2" />
</set>
<many-to-one name="Parent"
class="Base2"
column="ParentId"/>
<joined-subclass name="Base3" table="Base3" discriminator-value="-1" abstract="true">
<key column="BaseId" />
<discriminator column="ClassType" type="int" />
<many-to-one name="Foo"
class="Foo"
column="FooId"/>
<subclass name="RedClass" discriminator-value="1" />
<subclass name="BlueClass" discriminator-value="2" />
</joined-subclass>
</joined-subclass>
</class>
The problem is with Base3 and subclasses, since joined-subclass
doesn't permit the discriminator-value
attribute or the discriminator
child element.
I'd like to keep this structure since it's a good trade-off between storage efficiency and flexibility for the base of the hierarchy.