Hi,
First of all, I have subclasses with a discriminator working fine. When I load up a Person of type Employee it creates an Employee object for me, no problem[1].
My problem comes when I try to traverse a tree of these objects. I have a structure table, with person_id and person_parent_id. Starting with a Person (of whatever type) I can get all the Persons of which this Person is the parent (and I can recurse); but the Person that comes back from the PersonStructure domain object is a Person, not any particular subtype. So it looks like when the Person is loaded to populate the PersonStructure record it doesn't do any subclassing.
Does the Structure mapping file need to be told about the subclasses?
Snippet from Person.hbm.xml
Code:
<set name="personStructuresForPersonParentId" inverse="true" lazy="true" table="PERSON_STRUCTURE" fetch="select">
<key>
<column name="PERSON_PARENT_ID" not-null="true" />
</key>
<one-to-many class="eg.PersonStructure" />
</set>
<set name="personStructuresForPersonId" inverse="true" lazy="true" table="PERSON_STRUCTURE" fetch="select">
<key>
<column name="PERSON_ID" not-null="true" />
</key>
<one-to-many class="eg.PersonStructure" />
</set>
Snippet from PersonStructure.hbm.xml
Code:
<many-to-one name="personByPersonId" class="eg.Person" fetch="select">
<column name="PERSON_ID" not-null="true" />
</many-to-one>
<many-to-one name="personByPersonParentId" class="eg.Person" fetch="select">
<column name="PERSON_PARENT_ID" not-null="true" />
</many-to-one>
[1] although interestingly, despite the "discriminator-column" it still left outer joins all the subclass tables.