@@ -95,6 +95,10 @@ public override async Task ListAsync(IQueryExpression queryExpression, QueryPara
95
95
cancellationToken . ThrowIfCancellationRequested ( ) ;
96
96
using ( BeginProcess ( ) )
97
97
{
98
+ // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database,
99
+ // and the query may yield stale data.
100
+ await ( FlushAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
101
+
98
102
queryParameters . ValidateParameters ( ) ;
99
103
var plan = GetHQLQueryPlan ( queryExpression , false ) ;
100
104
@@ -127,6 +131,10 @@ public override async Task<IList<T>> ListAsync<T>(CriteriaImpl criteria, Cancell
127
131
cancellationToken . ThrowIfCancellationRequested ( ) ;
128
132
using ( BeginProcess ( ) )
129
133
{
134
+ // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database,
135
+ // and the query may yield stale data.
136
+ await ( FlushAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
137
+
130
138
string [ ] implementors = Factory . GetImplementors ( criteria . EntityOrClassName ) ;
131
139
int size = implementors . Length ;
132
140
@@ -252,6 +260,10 @@ public override async Task ListCustomQueryAsync(ICustomQuery customQuery, QueryP
252
260
cancellationToken . ThrowIfCancellationRequested ( ) ;
253
261
using ( BeginProcess ( ) )
254
262
{
263
+ // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database,
264
+ // and the query may yield stale data.
265
+ await ( FlushAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
266
+
255
267
var loader = new CustomLoader ( customQuery , Factory ) ;
256
268
257
269
var success = false ;
@@ -488,6 +500,10 @@ public async Task ManagedCloseAsync(CancellationToken cancellationToken)
488
500
cancellationToken . ThrowIfCancellationRequested ( ) ;
489
501
using ( BeginProcess ( ) )
490
502
{
503
+ // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database,
504
+ // and the get may miss an entity which should be there.
505
+ await ( FlushAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
506
+
491
507
object result = await ( Factory . GetEntityPersister ( entityName ) . LoadAsync ( id , null , lockMode ?? LockMode . None , this , cancellationToken ) ) . ConfigureAwait ( false ) ;
492
508
if ( temporaryPersistenceContext . IsLoadFinished )
493
509
{
@@ -563,6 +579,10 @@ public async Task ManagedCloseAsync(CancellationToken cancellationToken)
563
579
cancellationToken . ThrowIfCancellationRequested ( ) ;
564
580
using ( BeginProcess ( ) )
565
581
{
582
+ // We need to flush the batcher. Otherwise it may have pending operations which will not already have reached the database,
583
+ // and the query may yield stale data.
584
+ await ( FlushAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
585
+
566
586
IEntityPersister persister = GetEntityPersister ( entityName , entity ) ;
567
587
object id = persister . GetIdentifier ( entity ) ;
568
588
if ( log . IsDebugEnabled ( ) )
0 commit comments