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.
, there have been several bugfixes related to this in recent releases. Please let us know if this is still an issue using 5.2.14. If it is, then please attach a runnable test case that reproduces your issue. You can find test templates at: https://github.com/hibernate/hibernate-test-case-templates.
It seems has removed the double removing and replace it with single removing, so this ticket could have been fixed.