-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NULL references in joined table
PostPosted: Thu Jul 06, 2006 5:48 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 6:01 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
After reading more documentation I realized that the inverse="true" property in the join element is probably what is causing the references to not be updated. However I put that in to deal with another issue I had, a constraint violation, which I describe in this post: http://forum.hibernate.org/viewtopic.php?t=961392&highlight=

I seem to be between a rock and a hard place.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.