-->
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: Problem on Parent Child relationship
PostPosted: Tue Nov 18, 2003 2:09 am 
Newbie

Joined: Wed Nov 12, 2003 3:31 am
Posts: 9
Dear Sir/Madam,


I have a database schema with one table assoicate with another table.
Thus, I use the Parent and Child relationship according to the document stated in which Parent has a Collection Set of child. It worked fine in select statement. For Business requirement, the pk for both value must be application assigned. Thus, my pk generated is used "assigned" in the generator element. However, when I set to this, if I instantiate a new Parent with a new Child in the Parent's Collection Set, the Parent will be inserted but the Child is only do updated which is not expected. I found that I set the id of unsaved-value to null. When I change to unsaved-value to "any", the application will insert both new Parent and new Child. However, another problem come out, when I try to update a Parent together with a updated Child in the Parent Collection Set, the Parent will be updated but the Child will be inserted and that is not expected.

Thus, please help if I use generate key is "assigned", what need to be put in unsaved-value to make insert and update in a right manner or what recommendation I need to take.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 1:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In case of assigned, unsaved-value can't distinguish between a newly instantiated object (with an identifier assigned by the user) and an object loaded in a previous session. In these cases, you will probably need to give Hibernate a hint; either
* set unsaved-value="none" and explicitly save() newly instantiated children
* set unsaved-value="any" and explicitly update() loaded children

before calling update(parent). The first option is probably more sensible and so that is the default unsaved-value for assigned and composite identifiers.

There is one further possibility. There is a new Interceptor method named isUnsaved() which lets the application implement its own strategy for distinguishing newly instantiated objects

Next on section 8.4 of the reference guide

_________________
Emmanuel


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.