Parent entity tries to load transient child entity during cascade

Description

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):

Parent:

OtherParent:

Child:

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():

Stack trace:

Please advise how to further troubleshoot this issue, thank you.

Environment

None

Attachments

Assignee

Gail Badner

Reporter

Markus

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Critical
Configure