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: Avoiding parent key not found exception when saving child
PostPosted: Tue Apr 15, 2008 11:16 am 
Newbie

Joined: Tue Apr 15, 2008 10:59 am
Posts: 2
is it possible to insert parent when save is called on child? generally we get parent key not found exception when trying to insert child before parent is inserted. In our case we need to avoid exception and make sure parent is inserted for us if missing while inserting child. We can not explicitly handle save order due to abstract offline product functionality.


Top
 Profile  
 
 Post subject: Re: Avoiding parent key not found exception when saving chil
PostPosted: Tue Apr 15, 2008 11:52 am 
Beginner
Beginner

Joined: Tue Feb 26, 2008 2:04 pm
Posts: 28
Location: UK
yogeshgupte wrote:
is it possible to insert parent when save is called on child? generally we get parent key not found exception when trying to insert child before parent is inserted. In our case we need to avoid exception and make sure parent is inserted for us if missing while inserting child. We can not explicitly handle save order due to abstract offline product functionality.



Hi,

if you want to save a parent entity through a child entity you should use a cascade value of "save" or "save-or-update" (according to your needs) when mapping the parent entity in your child entity. Then if you have defined an auto-generated primary key strategy you shouldn't need to provide a key.

If you want to just save a child which is referencing an already existing parent then your best choice I think is to load the parent first set this to the child and then save the child.


cheers,


mosa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 3:41 am 
Newbie

Joined: Tue Apr 15, 2008 10:59 am
Posts: 2
Thanks much.


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.