I have a class AbstractPerson which joins two tables, PERSON and PERSON_APP_RELATIONSHIP. In PERSON_APP_RELATIONSHIP are references to other AbstractPersons: mother, father, husband, wife. I would prefer to keep those references in the PERSON table and not do a join but I do not have a choice to do this.
The class AbstractPerson looks like this:
Code:
public class AbstractPerson implements Person {
Long myId;
Person myMother;
Person myFather;
Person myHusband;
Person myWife;
...
}
And the mapping looks like this:
Code:
<class name="org.egcrc.cfr.common.AbstractPerson" table="PERSON" lazy="true" discriminator-value="-1">
<id name="myId" column="PERSON_PK" type="long" unsaved-value="null">
<generator class="native"/>
</id>
...
<join table="PERSON_APP_RELATIONSHIP" inverse="true">
<key column="PERSON_PK" not-null="true"/>
<many-to-one name="myFather" class="org.egcrc.cfr.common.AbstractPerson" column="FATHER_FK" cascade="save-update"/>
<many-to-one name="myMother" class="org.egcrc.cfr.common.AbstractPerson" column="MOTHER_FK" cascade="save-update"/>
<many-to-one name="myHusband" class="org.egcrc.cfr.common.AbstractPerson" column="HUSBAND_FK" cascade="save-update"/>
<many-to-one name="myWife" class="org.egcrc.cfr.common.AbstractPerson" column="WIFE_FK" cascade="save-update"/>
</join>
</class>
The problem is that when I save an AbstractPerson instance the foreign key references to the mother, father, husband, and wife in the PERSON_APP_RELATIONSHIP table do not get a value. The rows are inserted, but all of the values are null.
So I decided that I would change the schema to see if it would work without the join. I removed the <join> and allowed the <many-to-one> elements to appear directly in the AbstractPerson. If I use hbm2ddl to create the ddl I get a PERSON table that has the mother, father, husband, and wife foreign keys in it and there is no PERSON_APP_RELATIONSHIP table. Now when I save, the values are set for the foreign keys!
Does anyone have any clues why this is happening?
My setup: Java 1.5, Hibernate 3.1, DB2 8.x database.
TIA
Larry