saveOrUpdate() doesn't interact well with assigned identifiers, as you have
observed.

The solution is to use explicit save() or explicit update(). ie. the
application must decide wether the object is to be saved or updated, because
the identifier property can't give us any useful information.

----- Original Message -----
From: "Jeff Chong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, November 29, 2002 1:24 PM
Subject: unsaved-value for assigned identifier


> I have scenario here:
>
> I created 2 entity parent and child with one-to-many
> relationship
> The parent Id is generated from sequence table.
> But the children id is assigned.
>
> In the parent.xml, I have this
> <id .... unsaved-value="null">
> </id>
> <set ....>
>       <one-to-many ..... cascade="none" readonly="true">
> </set>
>
> In the child.xml, I have this
> <composite-id....unsaved-value="none">
> <composite-id>
>
> The setting I did this way having the reasons to
> 1. retrieve the parent at same time with children.
> 2. save the parent property and save the children EXPLICITLY.
>
> But, when I return the parent and at same time getChildren
> as Set.
> I need to update parent and one of the child only.
> So, I iterate the set collection and find the child.
> Then, I change the new value for one property and want to
> save using
> "save previous loaded object --> session.saveOrUpdate(child)
> " to store the child, I hit the errors saying: " Insert the
> duplicate key is not allow" which is error from database.
>
> >>Taken from the Hibernate FAQ:
>
> >> "I'm seeing foreign key constraint violations when using
> assigned >>identifiers Set unsaved-value="any" (the
> default). With other >>unsaved-value settings, Hibernate
> uses the value of the identifier >>property to judge if an
> instance already exists in the database. This >>conflicts
> with the use of assigned identifiers. "
>
>
> I suppose this is the problem I hit.  Is there any
> workaround to tell the hibernate to update instead of insert
> again?
>
> My current workaround is to retrieve the child explicitly
> and change the value at same time and only then the
> session.flush().....
>
> Cheers;
> Jeff
>
>
>
>
>
>
>
>



-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T 
handheld. Power & Color in a compact size! 
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to