From 12c7c448898652a186c1e76d7708177957e85414 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 6 Jun 2025 14:54:44 +0100 Subject: [PATCH] HHH-19526 Avoid generating a QueryInterpretationCache.Key when the query cache is disabled --- .../hibernate/query/sqm/internal/QuerySqmImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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() {