Invalid entity being created when merging with recursive cascading

Description

Consider 2 'parent' and 'child' entities:

There is a bidirectional relation with cascade=all on both sides. In some cases, on attempt to do a merge operation on a mixed (attached/transient) graph of these kind of entities, two managed entities are being created for single transient 'parent' entity.

The easiest way to see what's going on is to examine attached test.
Set breakpoint to bug.CascadeAttachedDetachedTest.java:70 and run this test. When breakpoint fires, examine contents of the 'managedVehicle' object (see attached managedVehicle_bad_transport.png):

Here we see two attached entities created for transient $2to3 entity. The first one (managedVehicle.transports[0]) is valid. The second one (managedVehicle.transports[0].pickupNode.pickupTransports[0]) is invalid (all fields, including ID is null). Next step (s.flush() ) will result in 'not-null property name is null' error for that entity.

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Alex Belyaev

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure