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
|