-->
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.  [ 3 posts ] 
Author Message
 Post subject: One-to many child object foreign key member update question
PostPosted: Fri Mar 12, 2004 4:15 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Hi all,

First of all, sorry fo the long subject, but it's the best way I could describe my question.

I'm using Hibernate 2.1.

I have a one-to-many relationship between tables A and B modelled in Oracle 9i such that each B record contains a field a_id, identifying the A record that the B record is associated with.

The corresponding Java object model consists of classes A and B, where A has a java.util.Collection member to contain B instances, and each B object has a member called aId, corresponding to th a_id attribute of the B table.

I've created the appropriate hbm.xml files, and I have had no problems using hibernate to insert, update or search for these objects. When I insert an A object that contains a Collection of B objects, the a_id column in the B table correctly references a record in the A table, but the aId members of the B objects in the Collection are not updated to with the id of their parent.

Should I expect the child foreign key members to be updated? If so, then I'd appreciate any thoughts regarding why they aren't getting updated now. This is the definition of the B collecition in A.hbm.xml

<set name="bSet" table="B" cascade="all">
<key column="a_id"/>
<one-to-many class="A"/>
</set>

Thanks in advance for your help,

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You should not handle ids, Hibernate is done for that.
add a <many-to-one name="a" column="ad_id"/> in your B mapping (you can access a_id using b.getA().getId()

And set the one-to-many inverse="true".

Refer the Parent / Child relationship chapter for more info.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 2:03 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Sounds good. Thanks for the help.

_________________
Mike Davison


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.