[hibernate-commits] Hibernate SVN: r15866 - core/trunk/core/src/main/java/org/hibernate/hql/ast/tree.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 3 09:22:51 EST 2009


Author: steve.ebersole at jboss.com
Date: 2009-02-03 09:22:51 -0500 (Tue, 03 Feb 2009)
New Revision: 15866

Modified:
   core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
Log:
HHH-3749 : limit FromElement reuse based on alias

Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2009-02-03 14:20:50 UTC (rev 15865)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2009-02-03 14:22:51 UTC (rev 15866)
@@ -434,7 +434,13 @@
 //
 ///////////////////////////////////////////////////////////////////////////////
 
-		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 @@
 			);
 		}
 		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 ) {




More information about the hibernate-commits mailing list