From 3e32e15c0a9e996e6ca093150f940b4f393f31cc Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 18 Mar 2021 18:17:08 +0100 Subject: [PATCH] Avoid new join sqm path creation when it already exists --- .../hql/internal/BasicDotIdentifierConsumer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java index 2c7aa949c2..8e8af26e9b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java @@ -144,13 +144,19 @@ public class BasicDotIdentifierConsumer implements DotIdentifierConsumer { // identifier is an "unqualified attribute reference" validateAsRoot( pathRootByExposedNavigable ); - final SqmPathSource subPathSource = pathRootByExposedNavigable.getReferencedPathSource().findSubPathSource( identifier ); - final SqmPath sqmPath = subPathSource.createSqmPath( pathRootByExposedNavigable, creationState ); + SqmPath sqmPath = pathRootByExposedNavigable.getImplicitJoinPath( identifier ); + if ( sqmPath == null ) { + final SqmPathSource subPathSource = pathRootByExposedNavigable.getReferencedPathSource() + .findSubPathSource( identifier ); + sqmPath = subPathSource.createSqmPath( pathRootByExposedNavigable, creationState ); + if ( !isTerminal ) { + pathRootByExposedNavigable.registerImplicitJoinPath( sqmPath ); + } + } if ( isTerminal ) { return sqmPath; } else { - pathRootByExposedNavigable.registerImplicitJoinPath( sqmPath ); return new DomainPathPart( sqmPath ); } }