diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java index c06a54b66b..1f874207e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java @@ -60,8 +60,7 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem } protected void copyTo(AbstractSqmPath target, SqmCopyContext context) { - assert lhs == null || lhs.getNavigablePath() == target.getLhs().getNavigablePath() - || getRoot( lhs ).getNodeType() instanceof SqmPolymorphicRootDescriptor; + assert navigablePathsMatch( target ); super.copyTo( target, context ); if ( reusablePaths != null ) { target.reusablePaths = new HashMap<>( reusablePaths.size() ); @@ -71,6 +70,13 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem } } + // meant for assertions only + private boolean navigablePathsMatch(AbstractSqmPath target) { + final SqmPath targetLhs = target.getLhs() != null ? target.getLhs() : target.findRoot(); + return lhs == null || lhs.getNavigablePath() == targetLhs.getNavigablePath() + || getRoot( lhs ).getNodeType() instanceof SqmPolymorphicRootDescriptor; + } + private SqmPath getRoot(SqmPath lhs) { return lhs.getLhs() == null ? lhs : getRoot( lhs.getLhs() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java index 08c786bec1..dd97275816 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmCrossJoin.java @@ -66,14 +66,13 @@ public class SqmCrossJoin extends AbstractSqmFrom implements JpaCrossJo if ( existing != null ) { return existing; } - final SqmRoot rootCopy = getRoot().copy( context ); final SqmCrossJoin path = context.registerCopy( this, new SqmCrossJoin<>( - getNavigablePathCopy( rootCopy ), + getNavigablePath(), getReferencedPathSource(), getExplicitAlias(), - rootCopy + getRoot().copy( context ) ) ); copyTo( path, context ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java index bb533a0840..beb87f5c65 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmDerivedJoin.java @@ -96,17 +96,16 @@ public class SqmDerivedJoin extends AbstractSqmQualifiedJoin implements if ( existing != null ) { return existing; } - final SqmRoot rootCopy = findRoot().copy( context ); final SqmDerivedJoin path = context.registerCopy( this, new SqmDerivedJoin<>( - getNavigablePathCopy( rootCopy ), + getNavigablePath(), subQuery, lateral, getReferencedPathSource(), getExplicitAlias(), getSqmJoinType(), - rootCopy + findRoot().copy( context ) ) ); copyTo( path, context ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java index d42d5a7041..416b3af497 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java @@ -70,15 +70,14 @@ public class SqmEntityJoin extends AbstractSqmQualifiedJoin implements if ( existing != null ) { return existing; } - final SqmRoot rootCopy = getRoot().copy( context ); final SqmEntityJoin path = context.registerCopy( this, new SqmEntityJoin<>( - getNavigablePathCopy( rootCopy ), + getNavigablePath(), getReferencedPathSource(), getExplicitAlias(), getSqmJoinType(), - rootCopy + getRoot().copy( context ) ) ); copyTo( path, context );