-->
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: cascade = "save-update"
PostPosted: Sat Feb 07, 2004 5:19 am 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
i have two objects, one is parent and one is child, both have "identity" key, and specifies "cascade=save-update" in the parent side of the one-to-many relationship.

I create a parent object A
then create a child object B
specify B as child of A (e.g. A.getBs().add(B);)
specify A as parent of B (e.g. B.setA(A);)

then I persist A

from the hibernate print out, i find that it does a insert of A, which is fine
Then It does an update of B instead of insert of B, which causes an error (as B has not been persisted before)

I try not to use cascade = save-update, and try to persist B before A. However, when persisting B, since the id of A is not generated yet, (it is "identity") the key of A cannot be correctly inserted in the record of B in the database.

Any ideas or suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 6:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Check your unsaved-value mapping


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 6:58 am 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
gloeglm wrote:
Check your unsaved-value mapping


Thx for your remind!

sorry that I read the documentation about unsaved-value, and know it is used to distinguish whether an object is newly instantiated object or transient object. But I still don't have very clear idea on how "any|none|null|id_value" could be used and their differences. I hope I can find some examples or more detailed illustrations on how to properly use them. Can anyone pass me some references or ideas? I found some concepts are very important to me but I cannot make it very clear from the documentation. Many Thank!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 7:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Sorry, don't really have time for a more in-depth explanation right now. Take a look at http://www.hibernate.org/hib_docs/reference/html/parent-child.html#parent-child-update


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.