diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java index e633e5c5e2..e8dcbb56db 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java @@ -1105,7 +1105,7 @@ public class ActionQueue { for ( int j = i - 1; j >= 0; j-- ) { BatchIdentifier prevBatchIdentifier = latestBatches.get( j ); if(prevBatchIdentifier.getParentEntityNames().contains( entityName )) { - latestBatches.remove( i ); + latestBatches.remove( batchIdentifier ); latestBatches.add( j, batchIdentifier ); } } @@ -1116,7 +1116,7 @@ public class ActionQueue { //Take care of unidirectional @OneToOne associations but exclude bidirectional @ManyToMany if(nextBatchIdentifier.getChildEntityNames().contains( entityName ) && !batchIdentifier.getChildEntityNames().contains( nextBatchIdentifier.getEntityName() )) { - latestBatches.remove( i ); + latestBatches.remove( batchIdentifier ); latestBatches.add( j, batchIdentifier ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingDuplicateTest.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingDuplicateTest.java index 88569dc548..6e4662abb5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingDuplicateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingDuplicateTest.java @@ -71,12 +71,13 @@ public class InsertOrderingDuplicateTest public void testBatching() throws SQLException { doInHibernate( this::sessionFactory, session -> { + SaleDocumentItem saleDocumentItem = new SaleDocumentItem(); + session.persist( saleDocumentItem ); + SaleDocumentSummary saleDocumentsummary = new SaleDocumentSummary(); session.persist(saleDocumentsummary); - SaleDocumentItem saleDocumentItem = new SaleDocumentItem(); saleDocumentsummary.addItem( saleDocumentItem ); - session.persist( saleDocumentItem ); Product product = new Product(); session.persist(product);