Author: steve.ebersole(a)jboss.com
Date: 2009-06-02 11:39:48 -0400 (Tue, 02 Jun 2009)
New Revision: 16667
Modified:
core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java
core/branches/Branch_3_2/test/org/hibernate/test/hql/WithClauseTest.java
Log:
HHH-1930 - QuerySyntaxException "with-clause expressions did not reference
from-clause element to which the with-clause was associated"
Modified: core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java 2009-06-02
15:39:21 UTC (rev 16666)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java 2009-06-02
15:39:48 UTC (rev 16667)
@@ -10,6 +10,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -43,7 +44,6 @@
import org.hibernate.hql.ast.tree.SelectClause;
import org.hibernate.hql.ast.tree.SelectExpression;
import org.hibernate.hql.ast.tree.UpdateStatement;
-import org.hibernate.hql.ast.tree.Node;
import org.hibernate.hql.ast.tree.OperatorNode;
import org.hibernate.hql.ast.tree.ParameterContainer;
import org.hibernate.hql.ast.util.ASTPrinter;
@@ -361,8 +361,7 @@
}
}
- private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws
SemanticException
- {
+ private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws
SemanticException {
try {
withClause( hqlWithNode );
AST hqlSqlWithNode = returnAST;
@@ -372,13 +371,22 @@
WithClauseVisitor visitor = new WithClauseVisitor( fromElement );
NodeTraverser traverser = new NodeTraverser( visitor );
traverser.traverseDepthFirst( hqlSqlWithNode );
- FromElement referencedFromElement = visitor.getReferencedFromElement();
- if ( referencedFromElement != fromElement ) {
- throw new InvalidWithClauseException( "with-clause expressions did not reference
from-clause element to which the with-clause was associated" );
+
+ String withClauseJoinAlias = visitor.getJoinAlias();
+ if ( withClauseJoinAlias == null ) {
+ withClauseJoinAlias = fromElement.getCollectionTableAlias();
}
+ else {
+ FromElement referencedFromElement = visitor.getReferencedFromElement();
+ if ( referencedFromElement != fromElement ) {
+ throw new InvalidWithClauseException( "with-clause expressions did not
reference from-clause element to which the with-clause was associated" );
+ }
+ }
+
SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() );
sql.whereExpr( hqlSqlWithNode.getFirstChild() );
- fromElement.setWithClauseFragment( visitor.getJoinAlias(), "(" +
sql.getSQL() + ")" );
+
+ fromElement.setWithClauseFragment( withClauseJoinAlias, "(" + sql.getSQL() +
")" );
}
catch( SemanticException e ) {
throw e;
@@ -866,8 +874,8 @@
}
ParameterNode parameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
- ( ( Node ) inputNode ).getLine(),
- ( ( Node ) inputNode ).getColumn(),
+ inputNode.getLine(),
+ inputNode.getColumn(),
positionalParameterCount++
);
parameter.setHqlParameterSpecification( paramSpec );
@@ -885,8 +893,8 @@
parameter.setText( "?" );
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
- ( ( Node ) delimiterNode ).getLine(),
- ( ( Node ) delimiterNode ).getColumn(),
+ delimiterNode.getLine(),
+ delimiterNode.getColumn(),
name
);
parameter.setHqlParameterSpecification( paramSpec );
@@ -961,9 +969,7 @@
}
public void addQuerySpaces(Serializable[] spaces) {
- for ( int i = 0; i < spaces.length; i++ ) {
- querySpaces.add( spaces[i] );
- }
+ querySpaces.addAll( Arrays.asList( spaces ) );
}
public Type[] getReturnTypes() {
Modified: core/branches/Branch_3_2/test/org/hibernate/test/hql/WithClauseTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/hql/WithClauseTest.java 2009-06-02
15:39:21 UTC (rev 16666)
+++ core/branches/Branch_3_2/test/org/hibernate/test/hql/WithClauseTest.java 2009-06-02
15:39:48 UTC (rev 16667)
@@ -125,6 +125,11 @@
.list();
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
+ //
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1930
+ list = s.createQuery( "from Human h inner join h.nickNames as nicknames with
nicknames = 'abc'" )
+ .list();
+ assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
+
txn.commit();
s.close();