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.  [ 4 posts ] 
Author Message
 Post subject: bidirectional association not working..
PostPosted: Wed Mar 22, 2006 1:20 am 
Newbie

Joined: Tue Mar 21, 2006 4:44 pm
Posts: 4
In my Parent.hbm.xml:
...
<set
name="children"
lazy="true"
inverse="true"
cascade="all"

>
<key>
<column name="parent_id" />
</key>

<one-to-many
class="Children"
/>
</set>

</class>
</hibernate-mapping>


In my Children.hbm.xml:
...
<many-to-one
name="parent"
class="Parent"
not-null="true"
>
<column name="parent_id" />
</many-to-one>



When I do session.saveOrUpdate(), everything get's populated Except the foreign key in Children table i.e parent_id value is shown null in the Children table.

Am trying these associations for the first time and am sure am doing something wrong in the hbm mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 4:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Make sure you have set the parent on each child as a part of the domain model creation before you save the parent.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 5:57 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Post your save code. david suggested you the right solution. Did you succeed ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 2:48 pm 
Newbie

Joined: Tue Mar 21, 2006 4:44 pm
Posts: 4
david wrote:
Make sure you have set the parent on each child as a part of the domain model creation before you save the parent.


It works when I set the Parent Explicitly from each of the Childern
using the Setters in the Children POJOs. I thought the combination of Cascade and Inverse in the mapping file should take care of such automatic updation of foreign keys?


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