I have a child entity that has two parent entities (the two parents itself have another common parent, but for simplicity I focus only on the three entities):
I use EntityManager.merge() to apply my changes:
if all objects are new, everything is fine
if OtherParent exists and Parent and Child are new, everything is fine
if OtherParent and Parent exist and Child is new, everything is fine
However if Parent already exists and OtherParent and Child are new, I get an EntityNotFoundException because directly after cascadeOnMerge() Parent tries to load Child (which INSERT has not been executed yet) in copyValues():
Please advise how to further troubleshoot this issue, thank you.