@@ -150,10 +150,12 @@ 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
+ // 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 );
157
159
batchingHelperSession = this ;
158
160
influencers = new LoadQueryInfluencers ( factory );
159
161
}
@@ -551,9 +553,12 @@ public CompletionStage<Void> reactiveInsertAll(Object... entities) {
551
553
552
554
@ Override
553
555
public CompletionStage <Void > reactiveInsertAll (int batchSize , Object ... entities ) {
556
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
557
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
554
558
final ReactiveConnection connection = batchingConnection ( batchSize );
555
559
return loop ( entities , batchingHelperSession ::reactiveInsert )
556
- .thenCompose ( v -> connection .executeBatch () );
560
+ .thenCompose ( v -> connection .executeBatch () )
561
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
557
562
}
558
563
559
564
@ Override
@@ -564,9 +569,12 @@ public CompletionStage<Void> reactiveUpdateAll(Object... entities) {
564
569
565
570
@ Override
566
571
public CompletionStage <Void > reactiveUpdateAll (int batchSize , Object ... entities ) {
572
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
573
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
567
574
final ReactiveConnection connection = batchingConnection ( batchSize );
568
575
return loop ( entities , batchingHelperSession ::reactiveUpdate )
569
- .thenCompose ( v -> connection .executeBatch () );
576
+ .thenCompose ( v -> connection .executeBatch () )
577
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
570
578
}
571
579
572
580
@ Override
@@ -577,9 +585,11 @@ public CompletionStage<Void> reactiveDeleteAll(Object... entities) {
577
585
578
586
@ Override
579
587
public CompletionStage <Void > reactiveDeleteAll (int batchSize , Object ... entities ) {
588
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
589
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
580
590
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 ) );
583
593
}
584
594
585
595
@@ -591,9 +601,12 @@ public CompletionStage<Void> reactiveRefreshAll(Object... entities) {
591
601
592
602
@ Override
593
603
public CompletionStage <Void > reactiveRefreshAll (int batchSize , Object ... entities ) {
604
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
605
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
594
606
final ReactiveConnection connection = batchingConnection ( batchSize );
595
607
return loop ( entities , batchingHelperSession ::reactiveRefresh )
596
- .thenCompose ( v -> connection .executeBatch () );
608
+ .thenCompose ( v -> connection .executeBatch () )
609
+ .whenComplete ( (v , throwable ) -> batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize ) );
597
610
}
598
611
599
612
private ReactiveConnection batchingConnection (int batchSize ) {
0 commit comments