HHH-3749 : limit FromElement reuse based on alias

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@15865 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-02-03 14:20:50 +00:00
parent 9ea2964908
commit 7a024374d6
1 changed files with 14 additions and 2 deletions

View File

@ -411,7 +411,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()
@ -435,13 +441,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 ) {