From reading the Javadoc of StatelessSession and the source of StatelessSessionImpl#insertMultiple it is our understanding that if JDBC batching is globally enabled then #insertMultiple should use the size of the List parameter as the batch size, rather than the global batch size. We are observing the opposite.
Here is what we are observing in detail:
We are on 7.4.14.Final and using a global batch size of 10 (hibernate.jdbc.batch_size=10). We are inserting 1000 entities using 10 calls to #insertMultiple, each with a list size of 100. Looking a the source of #insertMultiple we would expect 10 batch inserts, each with a batch size 100. However looking at flight recordings and JDBC trace logging we see that instead 100 batch inserts with a batch size of 10 are performed.
We managed to track the issue down to StandardMutationExecutorService#createExecutor. Rather than reading the JDBC batch size from SharedSessionContractImplementor it instead calls out to session.getJdbcCoordinator().getJdbcSessionOwner().getJdbcBatchSize(). We have a simple fix. However we are struggling with two issues:
- We are unsure about the wider implications of the fix.
./gradlew buildruns but that does not help assessing the impact. - We are struggling to come up with a test. We are aware of hibernate-test-case-templates but couldn’t find anything that helps counting batch inserts. We didn’t find any direct tests for
StandardMutationExecutorService, we could come up with one relaying heavily on mocking.