-->
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: Prent child problem
PostPosted: Wed Feb 14, 2007 10:55 am 
Newbie

Joined: Wed Feb 14, 2007 10:40 am
Posts: 5
Hi all,

I have created two tables with a parent child relationship between them. The problem comes when i try to store parent and child objects together. I am getting exception the foreign key in child table cannot be null.

I want to ask how can i store parent and child objects together in a single session?

Also i have included cascade="save-update" in the relationship property in both of .hbm files. and i have tried save(), saveOrUpdate(), persist() metods. Also keep in mind i am using hibernate with spring. In that i am using Hibernate template.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 12:28 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you need to set the parent in the child, and set it up in your mapping file. Whatever foreign key columns are:

Code:

<many-to-one
        name="parent"
        class="..."

        not-null="true"
    >
        <column name="column1" />
    </many-to-one>


------------
child.setParent(parent) 



_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.