@@ -128,7 +128,7 @@ public class ReactiveStatelessSessionImpl extends StatelessSessionImpl implement
128128
129129 private final ReactiveConnection reactiveConnection ;
130130
131- private final ReactiveStatelessSession batchingHelperSession ;
131+ private final ReactiveStatelessSessionImpl batchingHelperSession ;
132132
133133 private final PersistenceContext persistenceContext ;
134134
@@ -150,10 +150,9 @@ private ReactiveStatelessSessionImpl(
150150 PersistenceContext persistenceContext ) {
151151 super ( factory , options );
152152 this .persistenceContext = persistenceContext ;
153- Integer batchSize = getConfiguredJdbcBatchSize ();
154- reactiveConnection = batchSize == null || batchSize < 2
155- ? connection
156- : new BatchingConnection ( connection , batchSize );
153+ // Setting batch size to 0 because `StatelessSession` does not consider
154+ // the value of `hibernate.jdbc.batch_size`
155+ reactiveConnection = new BatchingConnection ( connection , 0 );
157156 batchingHelperSession = this ;
158157 influencers = new LoadQueryInfluencers ( factory );
159158 }
@@ -551,9 +550,12 @@ public CompletionStage<Void> reactiveInsertAll(Object... entities) {
551550
552551 @ Override
553552 public CompletionStage <Void > reactiveInsertAll (int batchSize , Object ... entities ) {
553+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
554+ batchingHelperSession .setJdbcBatchSize ( batchSize );
554555 final ReactiveConnection connection = batchingConnection ( batchSize );
555556 return loop ( entities , batchingHelperSession ::reactiveInsert )
556- .thenCompose ( v -> connection .executeBatch () );
557+ .thenCompose ( v -> connection .executeBatch () )
558+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
557559 }
558560
559561 @ Override
@@ -564,9 +566,12 @@ public CompletionStage<Void> reactiveUpdateAll(Object... entities) {
564566
565567 @ Override
566568 public CompletionStage <Void > reactiveUpdateAll (int batchSize , Object ... entities ) {
569+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
570+ batchingHelperSession .setJdbcBatchSize ( batchSize );
567571 final ReactiveConnection connection = batchingConnection ( batchSize );
568572 return loop ( entities , batchingHelperSession ::reactiveUpdate )
569- .thenCompose ( v -> connection .executeBatch () );
573+ .thenCompose ( v -> connection .executeBatch () )
574+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
570575 }
571576
572577 @ Override
@@ -577,9 +582,11 @@ public CompletionStage<Void> reactiveDeleteAll(Object... entities) {
577582
578583 @ Override
579584 public CompletionStage <Void > reactiveDeleteAll (int batchSize , Object ... entities ) {
585+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
586+ batchingHelperSession .setJdbcBatchSize ( batchSize );
580587 final ReactiveConnection connection = batchingConnection ( batchSize );
581- return loop ( entities , batchingHelperSession ::reactiveDelete )
582- .thenCompose ( v -> connection . executeBatch ( ) );
588+ return loop ( entities , batchingHelperSession ::reactiveDelete ). thenCompose ( v -> connection . executeBatch () )
589+ .whenComplete ( ( v , throwable ) -> batchingHelperSession . setJdbcBatchSize ( jdbcBatchSize ) );
583590 }
584591
585592
@@ -591,9 +598,12 @@ public CompletionStage<Void> reactiveRefreshAll(Object... entities) {
591598
592599 @ Override
593600 public CompletionStage <Void > reactiveRefreshAll (int batchSize , Object ... entities ) {
601+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
602+ batchingHelperSession .setJdbcBatchSize ( batchSize );
594603 final ReactiveConnection connection = batchingConnection ( batchSize );
595604 return loop ( entities , batchingHelperSession ::reactiveRefresh )
596- .thenCompose ( v -> connection .executeBatch () );
605+ .thenCompose ( v -> connection .executeBatch () )
606+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
597607 }
598608
599609 private ReactiveConnection batchingConnection (int batchSize ) {
0 commit comments