From f75882949014d6a57e06308e08b6b56b17324703 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 20 Feb 2025 17:21:01 +0100 Subject: [PATCH 1/2] [#2108] StatelessSession insertAll in batch does not do batching --- .../reactive/session/impl/ReactiveStatelessSessionImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java index 8e8e338a6..cf1271cb2 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java @@ -150,6 +150,9 @@ private ReactiveStatelessSessionImpl( PersistenceContext persistenceContext) { super( factory, options ); this.persistenceContext = persistenceContext; + // StatelessSessionImpl constructor sets the Jdbc Batch Size to 0, + // setting it to null allows getConfiguredJdbcBatchSize() to return correct configured size + setJdbcBatchSize( null ); Integer batchSize = getConfiguredJdbcBatchSize(); reactiveConnection = batchSize == null || batchSize < 2 ? connection From 6d3b45f385f4ab51131980ae40c9b891d39c543c Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Wed, 12 Feb 2025 10:57:21 +0100 Subject: [PATCH 2/2] [#2108] Add test for StatelessSession insertAll in batch does not do batching --- .../reactive/BatchingConnectionTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java index 0ce3d2e9d..dbacbed77 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java @@ -145,6 +145,29 @@ public void testBatching(VertxTestContext context) { ); } + @Test + public void testBatchingWithStateless(VertxTestContext context) { + final GuineaPig[] pigs = { + new GuineaPig( 11, "One" ), + new GuineaPig( 22, "Two" ), + new GuineaPig( 33, "Three" ), + new GuineaPig( 44, "Four" ), + new GuineaPig( 55, "Five" ), + new GuineaPig( 66, "Six" ), + }; + test( context, getMutinySessionFactory() + .withStatelessTransaction( s -> s.insertAll( 10, pigs ) ) + .invoke( () -> { + // We expect only one insert query + assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 ); + // Parameters are different for different dbs, so we cannot do an exact match + assertThat( sqlTracker.getLoggedQueries().get( 0 ) ) + .matches("insert into pig \\(name,version,id\\) values (.*)" ); + sqlTracker.clear(); + } ) + ); + } + @Test public void testBatchingConnection(VertxTestContext context) { test( context, openSession()