-->
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.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException primitive identifiers
PostPosted: Fri Apr 29, 2005 3:33 pm 
Newbie

Joined: Mon Oct 04, 2004 5:09 pm
Posts: 4
I just wanted to post this in an effort to help others that may run across the same problem.

I have an entity A which contains a collection of other entities B.
When adding newly created transient entities B, to persistent entity A, and attempting to save them, I was getting the dreaded NonUniqueObjectException.

After searching this forum and then digging through Hibernate In Action (thanks Christian and Gavin) I found the following:

<paraphrase>
If your using primitive values as identifiers, then make sure you provide the unsaved-value attribute of the id element with a value which will allow Hibernate to identify newly created transient entities.
</paraphrase>

Well, I had forgotten that Hibernate assumes you are using objects and NOT primitives as identities and defaults to checking for null; otherwise it assumes that it has a persistent instance. I was indeed using primitive values for identities in my objects. I went back and added the unsaved-value="0" and it worked.

So there you have it. BTW, Hibernate In Action is well worth the price. It has served as a most valuable reference.

/robert


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.