We're updating the issue view to help you get more done. 

Hibernate ActionQueue.sort() removes entities from insertion batches

Description

When committing transaction with batch insertions using SessionFactory, there is an error in ActionQueue.InsertActionSorter.sort(insertions), where could be some entities from batches removed. Lines 759 - 815 in Hibernate 5.2.10.Final. When in inner loop is called this.latestBatches.remove more than once, then some entity could have multiple occurence in this.latestBatches, other one could disappear.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 for(int i = 0; i < this.latestBatches.size(); ++i) { batchIdentifier = (ActionQueue.InsertActionSorter.BatchIdentifier)this.latestBatches.get(i); String entityName = batchIdentifier.getEntityName(); int j; ActionQueue.InsertActionSorter.BatchIdentifier nextBatchIdentifier; for(j = i - 1; j >= 0; --j) { nextBatchIdentifier = (ActionQueue.InsertActionSorter.BatchIdentifier)this.latestBatches.get(j); if (nextBatchIdentifier.getParentEntityNames().contains(entityName)) { this.latestBatches.remove(i); this.latestBatches.add(j, batchIdentifier); } } for(j = i + 1; j < this.latestBatches.size(); ++j) { nextBatchIdentifier = (ActionQueue.InsertActionSorter.BatchIdentifier)this.latestBatches.get(j); if (nextBatchIdentifier.getChildEntityNames().contains(entityName) && !batchIdentifier.getChildEntityNames().contains(nextBatchIdentifier.getEntityName())) { this.latestBatches.remove(i); this.latestBatches.add(j, batchIdentifier); } } }

Environment

None

Status

Assignee

Unassigned

Reporter

Martin Kožený

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.0.12

Components

Affects versions

5.1.0
5.2.7
5.1.1
5.2.4
5.1.7
5.1.4
5.2.5
5.1.9
5.2.11
5.2.1
5.2.9
5.2.10
5.2.8
5.1.3
5.1.2
5.2.2
5.2.0
5.1.5
5.2.6
5.1.6
5.2.3
5.1.8

Priority

Critical