Problem with ActionQueue#InsertActionSorter throws FK exception

Description

ActionQueue#InsertActionSorter fails to generate right order:
Referential integrity constraint violation: "FKQ3H4GCPRJB128BSIUCBII8687: PUBLIC.SALEDOCUMENTITEM FOREIGN KEY(ID_SUBJECT) REFERENCES PUBLIC.OPERATIONREGISTRYSUBJECT(ID) (3)"; SQL statement:
insert into SaleDocumentItem (lp, product_id, quantity, ID_SALE_DOCUMENT, ID_SUBJECT, id) values (?, ?, ?, ?, ?, ?) [23506-176]

Because of https://hibernate.atlassian.net/browse/HHH-11634 we use 5.2.11-SNAPSHOT version which
I downloaded from Jenkins (http://ci.hibernate.org/view/ORM/job/hibernate-orm-master-pgsql/645/) but error also occurs in versions from issue's description

TestCase:
https://github.com/MirekSz/HHH-11939

In tests hibernate.order_inserts=true which provoke error when I change to false everything works fine

Environment

None

Status

Assignee

Unassigned

Reporter

Mirek

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.2.19
5.0.10

Components

Affects versions

5.2.10
5.1.9
5.2.11

Priority

Critical