Hibernate sees two detached objects here. Since it didn't load either of them, it doesn't know if they have real representations in the database. When it goes to merge them, it sees that both do not have database representations, and it then creates the db representation, and it creates new ids for both, since each new record is told to use an id from the sequence.
Can you load the one record first, and then merge the new one and see what happens?
Just an idea. I'm speaking purely out of ignorance on this one.
I'm suggesting this not as a final solution, but to see what happens when you initially load an object, and then do a merge. That way you don't have transient objects, but instead, are merging a transient object with a persistent objects.
Doing this as a test case might help you solve your problem, and discover what is going wrong. Then you can adopt your final solution as fit.
It's just an idea. I'd be curious as to why you can't do a test that loads one entity first?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop