In a particular case as described below, order-inserts = true causes FK Violation, while order-inserts = false does not:
A entity refers to B entity in a OneToOne unidirectional relationship
P entity refers to Q entity in a OneToOne unidirectional relationship
A refers to a list of P entities in a OneToMany relationship, the ID of A is stored in P. P does not have an object reference to A in the class definition.
All above entities have auto-generated/db-generated IDs
When executing the following operations in order an FK violation occurs:
Persist Q [Not required if cascadetype = persist on P->Q]
Set ID of A in P
Persist P [We only need 1 P to reproduce this issue]
Due to fixes made in ActionQueue to solve issue HHH-13068, the order of the above insert statements is now flawed. While inserts should be in order: BAQP, inserts are instead sorted into order QPBA causing an FK Violation in P's FK reference to A.
This issue is reproducable on versions with the fix, that being versions 5.4.1 and 5.4.2. This issue does not occur in previous versions.
Attached testcase as
This issue is due to below code in ActionQueue as nextBatchIdentifier.parent is assigned a parent. There can be multiple parents but with this code only one parent reference is being hold.
Fix: parent should be added to nextBatchIdentifier.parentEntityNames
I’ll create pull request soon
Thanks ! Merged in master and backported to 5.4