hi,
back from holiday, back to my beloved NonUniqueObjectException.
I extracted a test-case that illustrates my problem. many thanks to those making the effort to look at it. your help is much appreciated. you'll find it at
http://inmeco.de/snippets/NonUniqueObje ... stCase.zip
in my oppinion, this is a normal use-case:
I have a User that is looged in, thus held over multiple hibernate-sessions. This user is added to Issue (1:m User:Issue) and a Issue is related to a Version (1:m Version:Issue). Works fine, but when adding a new Issue to a Version freshly loaded from DB, hibernate says, my user - associated to the new Issue - is not unique. Of course it is not, because it is loaded with the Version from DB AND is still held by my app, of course I could reload the user using the id, but I do have many of those session-spanning entities, because each user-interaction opens a seperate hibernate-session and a entity may be persisted after many such interactions. I think I see my mistake, but I can figure out how to approach this in a better way. the same thing with loading entities. I have a entity loaded from db that is related to another one. when I laod the other entity I have the same problem... two instances of a single entity. I can't know each entity that is referenced by some other! how about special criteria when querying for an entity? how am I expected to load it? dive into my model of many entities and look for one with the same id? that is not cool!
I basically see two options:
[i] I could implement long-run hibernate-sessions and trash my 'TransientObjects'. But this is discouraged by documentation.
[ii] I could catch that exception and reload the entity from database, fill it with data from the 'broken' transient-object and do so for each of its related entities.
[iii] ejb :)?
[iv] request a hibernate-feature that allows to 'park' entities that are modified in multiple session, but get persisted only if the user presses 'save'. a kind of long-running super-session?
[v] request a hibernate-feature that allows hooking entity-retrieval, so my TransientObject-Manager is asked by hibernate for an entity with a certain uid?
thank you
marie