From 89cf22bab6bbd5aa317ca7a1df63624bb7b677c4 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 3 Feb 2009 14:23:14 +0000 Subject: [PATCH] HHH-3749 : limit FromElement reuse based on alias git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@15867 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../java/org/hibernate/hql/ast/tree/DotNode.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java b/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java index 2d859837d2..eb807284ff 100644 --- a/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java +++ b/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java @@ -434,7 +434,13 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec // /////////////////////////////////////////////////////////////////////////////// - if ( elem == null ) { + boolean found = elem != null; + // even though we might find a pre-existing element by join path, for FromElements originating in a from-clause + // we should only ever use the found element if the aliases match (null != null here). Implied joins are + // always (?) ok to reuse. + boolean useFoundFromElement = found && ( elem.isImplied() || areSame( classAlias, elem.getClassAlias() ) ); + + if ( ! useFoundFromElement ) { // If this is an implied join in a from element, then use the impled join type which is part of the // tree parser's state (set by the gramamar actions). JoinSequence joinSequence = getSessionFactoryHelper() @@ -458,13 +464,19 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec ); } else { - currentFromClause.addDuplicateAlias(classAlias, elem); + // NOTE : addDuplicateAlias() already performs nullness checks on the alias. + currentFromClause.addDuplicateAlias( classAlias, elem ); } setImpliedJoin( elem ); getWalker().addQuerySpaces( elem.getEntityPersister().getQuerySpaces() ); setFromElement( elem ); // This 'dot' expression now refers to the resulting from element. } + private boolean areSame(String alias1, String alias2) { + // again, null != null here + return !StringHelper.isEmpty( alias1 ) && !StringHelper.isEmpty( alias2 ) && alias1.equals( alias2 ); + } + private void setImpliedJoin(FromElement elem) { this.impliedJoin = elem; if ( getFirstChild().getType() == SqlTokenTypes.DOT ) {