-->
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: One-to-many Foreign Key Association
PostPosted: Tue Jul 11, 2006 6:05 pm 
Newbie

Joined: Mon Jul 03, 2006 12:59 pm
Posts: 6
With a one-to-many association where the primary key of the parent maps to part of the primary key of the children, how do you save the children??

The problem is the primary key is genereted by a sequence, so the corresponding field will not be set in the children objects -- it will be null at the time of insert.

Since it is null, the rows cannot be inserted with a partially null primary key. How to people solve this; I imagine it is fairly common????


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 6:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Code:
<class name="Parent" ...>
  <id column="ParentID" ...>
  ...
  <set name="Children" inverse="false">
    <key name="ParentID" not-null="true"/>
    <one-to-many class="Child"/>
  </set>
  ...
</class>

<class name="Child" ...>
  <composite-id>
    <key-property name="ChildID" .../>
    <key-many-to-one name="Parent" class="Parent" column="ParentID"/>
  </composite-id>

  ...
</class>
You can also make the composite-id named. See section 5.1.5 of the ref docs.

_________________
Code tags are your friend. Know them and use them.


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.