@@ -128,7 +128,7 @@ public class ReactiveStatelessSessionImpl extends StatelessSessionImpl implement
128
128
129
129
private final ReactiveConnection reactiveConnection ;
130
130
131
- private final ReactiveStatelessSession batchingHelperSession ;
131
+ private final ReactiveStatelessSessionImpl batchingHelperSession ;
132
132
133
133
private final PersistenceContext persistenceContext ;
134
134
@@ -150,10 +150,9 @@ private ReactiveStatelessSessionImpl(
150
150
PersistenceContext persistenceContext ) {
151
151
super ( factory , options );
152
152
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 );
157
156
batchingHelperSession = this ;
158
157
influencers = new LoadQueryInfluencers ( factory );
159
158
}
@@ -551,9 +550,12 @@ public CompletionStage<Void> reactiveInsertAll(Object... entities) {
551
550
552
551
@ Override
553
552
public CompletionStage <Void > reactiveInsertAll (int batchSize , Object ... entities ) {
553
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
554
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
554
555
final ReactiveConnection connection = batchingConnection ( batchSize );
555
556
return loop ( entities , batchingHelperSession ::reactiveInsert )
556
- .thenCompose ( v -> connection .executeBatch () );
557
+ .thenCompose ( v -> connection .executeBatch () )
558
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
557
559
}
558
560
559
561
@ Override
@@ -564,9 +566,12 @@ public CompletionStage<Void> reactiveUpdateAll(Object... entities) {
564
566
565
567
@ Override
566
568
public CompletionStage <Void > reactiveUpdateAll (int batchSize , Object ... entities ) {
569
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
570
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
567
571
final ReactiveConnection connection = batchingConnection ( batchSize );
568
572
return loop ( entities , batchingHelperSession ::reactiveUpdate )
569
- .thenCompose ( v -> connection .executeBatch () );
573
+ .thenCompose ( v -> connection .executeBatch () )
574
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
570
575
}
571
576
572
577
@ Override
@@ -577,9 +582,11 @@ public CompletionStage<Void> reactiveDeleteAll(Object... entities) {
577
582
578
583
@ Override
579
584
public CompletionStage <Void > reactiveDeleteAll (int batchSize , Object ... entities ) {
585
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
586
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
580
587
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 ) );
583
590
}
584
591
585
592
@@ -591,9 +598,12 @@ public CompletionStage<Void> reactiveRefreshAll(Object... entities) {
591
598
592
599
@ Override
593
600
public CompletionStage <Void > reactiveRefreshAll (int batchSize , Object ... entities ) {
601
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
602
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
594
603
final ReactiveConnection connection = batchingConnection ( batchSize );
595
604
return loop ( entities , batchingHelperSession ::reactiveRefresh )
596
- .thenCompose ( v -> connection .executeBatch () );
605
+ .thenCompose ( v -> connection .executeBatch () )
606
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
597
607
}
598
608
599
609
private ReactiveConnection batchingConnection (int batchSize ) {
0 commit comments