Hi,
I'm trying to implement a simple class inheritance mapping. I have one parent class and two subclasses which are mapped by the table per subclass strategy. The mapping looks like the following:
Code:
<hibernate-mapping>
<class name="Parent" table="Parent">
<id name="PID" type="java.lang.Integer">
<column name="PID"/>
<generator class="increment" />
</id>
<property name="description" column="description" type="java.lang.String" />
<one-to-one name="location" class="Location" column="location"/>
<joined-subclass name="Male" table="Male">
<key column="PID"/>
<one-to-one name="Female" class="Female" column="female"/>
</joined-subclass>
<joined-subclass name="Female" table="Female">
<key column="PID"/>
<one-to-one name="Male" class="Male" column="male"/>
</joined-subclass>
</class>
</hibernate-mapping>
I have filled the database with some test data.
9 entries in the parent table (PID from 1 to 9)
3 entries in the male table (PID 1,3,7)
6 entries in the female table (PID 2,4,5,6,8,9)
Now I'm trying to read the property location from a given Parent object. I use getLocation(). But then Hibernate throws the following HibernateException:
Code:
org.hibernate.HibernateException: More than one row with the given identifier was found: 9, for class: Parent
Well, I can't figure out why Hibernate complains about this particular entry, but not about other entries.
Should I use another mapping strategy? Or am I missing something important?
Thanks,
Tino