Fix NPE with cache key

This commit is contained in:
Andrea Boriero 2021-09-15 09:30:16 +02:00
parent 16f4a10908
commit ac1123be05
2 changed files with 21 additions and 9 deletions

View File

@ -348,13 +348,23 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
cacheMode.name()
);
cachedResults = null;
queryResultsCacheKey = null;
if ( queryCacheEnabled ) {
queryResultsCacheKey = QueryKey.from(
jdbcSelect.getSql(),
executionContext.getQueryOptions().getLimit(),
executionContext.getQueryParameterBindings(),
session
);
}
else {
queryResultsCacheKey = null;
}
}
if ( cachedResults == null ) {
return new JdbcValuesResultSetImpl(
resultSetAccess,
canBeCached ? queryResultsCacheKey : null,
canBeCached && queryCacheEnabled ? queryResultsCacheKey : null,
queryIdentifier,
executionContext.getQueryOptions(),
jdbcValuesMapping,

View File

@ -52,13 +52,15 @@ public class QueryCachePutManagerEnabledImpl implements QueryCachePutManager {
@Override
public void finishUp(SharedSessionContractImplementor session) {
final boolean put = queryCache.put(
queryKey,
dataToCache,
session
);
if ( put && statistics.isStatisticsEnabled() ) {
statistics.queryCachePut( queryIdentifier, queryCache.getRegion().getName() );
if ( queryKey != null ) {
final boolean put = queryCache.put(
queryKey,
dataToCache,
session
);
if ( put && statistics.isStatisticsEnabled() ) {
statistics.queryCachePut( queryIdentifier, queryCache.getRegion().getName() );
}
}
}
}