Hi,
I am combining table-per-class inheritance and table-per-class-hierarchy inheritance as follows:
<class name="Universe" table="universe">
<id name="id" column="universe_id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<set name="dimensions" inverse="true" cascade="all-delete-orphan" lazy="false" >
<key column="universe_id" />
<one-to-many class="Dimension"/>
</set>
</class>
<class name="Region" table="region">
<id name="id" column="region_id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<discriminator column="discriminator" type="string"/>
<subclass name="Dimension" discriminator-value="D">
<join table="dimension">
<key column="region_id"/>
<many-to-one name="universe" column="universe_id" class="Universe" not-null="true" />
<property name="name" column="name" type="java.lang.String"/>
</join>
</subclass>
<subclass name="AsteroidBelt" ..>
</class>
The first class has a collection of Dimensions. The foreign key to a Universe of a Dimension is within the subclass table "dimension". Now, persisting a universe with dimensions goes fine, but when I try to load it,
I get the error "Unknown column 'dimensies0.universe_id' in 'field list'", although the column 'universe_id' is in the joined subclass table.
It seems when trying to fetch the dimensions collection, Hibernate ignores the properties defined in the joined table and so does not find the universe_id column.
Is this expected behaviour or a bug? And is there an elegant workaround for this? Right now, I moved the universe_id column to the region table and made it nullable. It works, but it doesn't really feel satisfying.
I am using MySql Server 5.0 and Hibernate 3.0.5.
|