I'm getting a similar problem when mixing inheritence strategies of subclass and join (as described in the reference document). As I have a large class structure, and I want to avoid lengthy SQL select statements, I have chosen the discriminator strategy. I admit, I've never used it before, so, hopefully, this problem is down to my implementation.
The mapping below is for an entity that sub-classes AbstractOrgEntity using the discriminator method. The OrgUnit has a parent/child relation with entities of the same type, but this is reflected only in the table ORGUNIT and not the table of AbstractOrgEntity.
When I try and retrieve the sub-units of a given OrgUnit, the SQL generated incorrectly references a non-existent PARENT_ID column in the AbstractOrgEntity table.
The problem would seem to be that the <set> for subUnits is not within the <join> element, and so Hibernate assumes the property belongs to the AbstractOrgEntity table. Unfortunately, you can't place the <set> within the <join> as the XML schema disallows it - and I guess Hibernate would complain even if the schema didn't.
I don't think this is a bug as more of an oversight.
Does anyone have a work-around?
Code:
<hibernate-mapping>
<subclass name="OrgUnit" extends="AbstractOrgEntity" discriminator-value="12">
<!-- bi-directional one-to-many composite association to OrgUnitType -->
<!-- this is the parent reference to its children -->
<set name="subUnits" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="PARENT_ID"/>
<one-to-many class="OrgUnit"/>
</set>
<join table="ORGUNIT">
<key column="id"/>
<property name="description" column="DESCRIPTION" type="string"/>
<!-- bi-directional many-to-one composite association to OrgUnitType -->
<!-- this is the child reference to the parent -->
<many-to-one name="parent" column="PARENT_ID"
class="OrgUnit" not-found="ignore" not-null="false"/>
</join>
</subclass>
</hibernate-mapping>