@@ -150,10 +150,12 @@ 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+ // Don't know why ORM set the batch size to 0 in the super constructor,
154+ // but the default should be the one in the factory options
155+ int defaultBatchSize = factory .getSessionFactoryOptions ().getJdbcBatchSize ();
156+ setJdbcBatchSize ( defaultBatchSize );
157+ // BatchingConnection will use the original connection if defaultBatchSize <= 1
158+ reactiveConnection = new BatchingConnection ( connection , defaultBatchSize );
157159 batchingHelperSession = this ;
158160 influencers = new LoadQueryInfluencers ( factory );
159161 }
@@ -551,9 +553,12 @@ public CompletionStage<Void> reactiveInsertAll(Object... entities) {
551553
552554 @ Override
553555 public CompletionStage <Void > reactiveInsertAll (int batchSize , Object ... entities ) {
556+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
557+ batchingHelperSession .setJdbcBatchSize ( batchSize );
554558 final ReactiveConnection connection = batchingConnection ( batchSize );
555559 return loop ( entities , batchingHelperSession ::reactiveInsert )
556- .thenCompose ( v -> connection .executeBatch () );
560+ .thenCompose ( v -> connection .executeBatch () )
561+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
557562 }
558563
559564 @ Override
@@ -564,9 +569,12 @@ public CompletionStage<Void> reactiveUpdateAll(Object... entities) {
564569
565570 @ Override
566571 public CompletionStage <Void > reactiveUpdateAll (int batchSize , Object ... entities ) {
572+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
573+ batchingHelperSession .setJdbcBatchSize ( batchSize );
567574 final ReactiveConnection connection = batchingConnection ( batchSize );
568575 return loop ( entities , batchingHelperSession ::reactiveUpdate )
569- .thenCompose ( v -> connection .executeBatch () );
576+ .thenCompose ( v -> connection .executeBatch () )
577+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
570578 }
571579
572580 @ Override
@@ -577,9 +585,11 @@ public CompletionStage<Void> reactiveDeleteAll(Object... entities) {
577585
578586 @ Override
579587 public CompletionStage <Void > reactiveDeleteAll (int batchSize , Object ... entities ) {
588+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
589+ batchingHelperSession .setJdbcBatchSize ( batchSize );
580590 final ReactiveConnection connection = batchingConnection ( batchSize );
581- return loop ( entities , batchingHelperSession ::reactiveDelete )
582- .thenCompose ( v -> connection . executeBatch ( ) );
591+ return loop ( entities , batchingHelperSession ::reactiveDelete ). thenCompose ( v -> connection . executeBatch () )
592+ .whenComplete ( ( v , throwable ) -> batchingHelperSession . setJdbcBatchSize ( jdbcBatchSize ) );
583593 }
584594
585595
@@ -591,9 +601,12 @@ public CompletionStage<Void> reactiveRefreshAll(Object... entities) {
591601
592602 @ Override
593603 public CompletionStage <Void > reactiveRefreshAll (int batchSize , Object ... entities ) {
604+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
605+ batchingHelperSession .setJdbcBatchSize ( batchSize );
594606 final ReactiveConnection connection = batchingConnection ( batchSize );
595607 return loop ( entities , batchingHelperSession ::reactiveRefresh )
596- .thenCompose ( v -> connection .executeBatch () );
608+ .thenCompose ( v -> connection .executeBatch () )
609+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
597610 }
598611
599612 private ReactiveConnection batchingConnection (int batchSize ) {
0 commit comments