HHH-17742 Fix race condition in ConcreteSqmSelectQueryPlan

This commit is contained in:
Ken Schosinsky 2024-02-16 15:08:17 +01:00 committed by Christian Beikov
parent a3ca11a363
commit 3bda3adc4f
1 changed files with 19 additions and 0 deletions

View File

@ -333,6 +333,25 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
localCopy.firstParameterBindings = null;
cacheableSqmInterpretation = localCopy;
}
else {
// If the translation depends on parameter bindings or it isn't compatible with the current query options,
// we have to rebuild the JdbcSelect, which is still better than having to translate from SQM to SQL AST again
if ( localCopy.jdbcSelect.dependsOnParameterBindings() ) {
jdbcParameterBindings = createJdbcParameterBindings( localCopy, executionContext );
}
// If the translation depends on the limit or lock options, we have to rebuild the JdbcSelect
// We could avoid this by putting the lock options into the cache key
if ( !localCopy.jdbcSelect.isCompatibleWith( jdbcParameterBindings, executionContext.getQueryOptions() ) ) {
localCopy = buildCacheableSqmInterpretation(
sqm,
domainParameterXref,
executionContext
);
jdbcParameterBindings = localCopy.firstParameterBindings;
localCopy.firstParameterBindings = null;
cacheableSqmInterpretation = localCopy;
}
}
}
}
else {