diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java index 05ec67530773..123340409ed2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java @@ -490,10 +490,16 @@ public boolean isQueryPlanCacheable() { } private SelectQueryPlan resolveSelectQueryPlan() { - final QueryInterpretationCache.Key cacheKey = createInterpretationsKey( this ); - return cacheKey != null - ? interpretationCache().resolveSelectQueryPlan( cacheKey, this::buildSelectQueryPlan ) - : buildSelectQueryPlan(); + final QueryInterpretationCache queryCache = interpretationCache(); + if ( queryCache.isEnabled() ) { + final QueryInterpretationCache.Key cacheKey = createInterpretationsKey( this ); + return cacheKey != null + ? queryCache.resolveSelectQueryPlan( cacheKey, this::buildSelectQueryPlan ) + : buildSelectQueryPlan(); + } + else { + return buildSelectQueryPlan(); + } } private QueryInterpretationCache interpretationCache() {