HHH-1930 - QuerySyntaxException "with-clause expressions did not reference from-clause element to which the with-clause was associated"
git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@16666 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
6ad0642dba
commit
ea87fdaef8
|
@ -66,7 +66,6 @@ import org.hibernate.hql.ast.tree.RestrictableStatement;
|
||||||
import org.hibernate.hql.ast.tree.SelectClause;
|
import org.hibernate.hql.ast.tree.SelectClause;
|
||||||
import org.hibernate.hql.ast.tree.SelectExpression;
|
import org.hibernate.hql.ast.tree.SelectExpression;
|
||||||
import org.hibernate.hql.ast.tree.UpdateStatement;
|
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.OperatorNode;
|
||||||
import org.hibernate.hql.ast.tree.ParameterContainer;
|
import org.hibernate.hql.ast.tree.ParameterContainer;
|
||||||
import org.hibernate.hql.ast.util.ASTPrinter;
|
import org.hibernate.hql.ast.util.ASTPrinter;
|
||||||
|
@ -382,9 +381,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
||||||
log.debug( "createFromJoinElement() : " + getASTPrinter().showAsString( fromElement, "-- join tree --" ) );
|
log.debug( "createFromJoinElement() : " + getASTPrinter().showAsString( fromElement, "-- join tree --" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws SemanticException {
|
||||||
private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws SemanticException
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
withClause( hqlWithNode );
|
withClause( hqlWithNode );
|
||||||
AST hqlSqlWithNode = returnAST;
|
AST hqlSqlWithNode = returnAST;
|
||||||
|
@ -394,13 +391,22 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
||||||
WithClauseVisitor visitor = new WithClauseVisitor( fromElement );
|
WithClauseVisitor visitor = new WithClauseVisitor( fromElement );
|
||||||
NodeTraverser traverser = new NodeTraverser( visitor );
|
NodeTraverser traverser = new NodeTraverser( visitor );
|
||||||
traverser.traverseDepthFirst( hqlSqlWithNode );
|
traverser.traverseDepthFirst( hqlSqlWithNode );
|
||||||
FromElement referencedFromElement = visitor.getReferencedFromElement();
|
|
||||||
if ( referencedFromElement != fromElement ) {
|
String withClauseJoinAlias = visitor.getJoinAlias();
|
||||||
throw new InvalidWithClauseException( "with-clause expressions did not reference from-clause element to which the with-clause was associated" );
|
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() );
|
SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() );
|
||||||
sql.whereExpr( hqlSqlWithNode.getFirstChild() );
|
sql.whereExpr( hqlSqlWithNode.getFirstChild() );
|
||||||
fromElement.setWithClauseFragment( visitor.getJoinAlias(), "(" + sql.getSQL() + ")" );
|
|
||||||
|
fromElement.setWithClauseFragment( withClauseJoinAlias, "(" + sql.getSQL() + ")" );
|
||||||
}
|
}
|
||||||
catch( SemanticException e ) {
|
catch( SemanticException e ) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -888,8 +894,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
||||||
}
|
}
|
||||||
ParameterNode parameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
|
ParameterNode parameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
|
||||||
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
|
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
|
||||||
( ( Node ) inputNode ).getLine(),
|
inputNode.getLine(),
|
||||||
( ( Node ) inputNode ).getColumn(),
|
inputNode.getColumn(),
|
||||||
positionalParameterCount++
|
positionalParameterCount++
|
||||||
);
|
);
|
||||||
parameter.setHqlParameterSpecification( paramSpec );
|
parameter.setHqlParameterSpecification( paramSpec );
|
||||||
|
@ -907,8 +913,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
||||||
parameter.setText( "?" );
|
parameter.setText( "?" );
|
||||||
|
|
||||||
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
|
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
|
||||||
( ( Node ) delimiterNode ).getLine(),
|
delimiterNode.getLine(),
|
||||||
( ( Node ) delimiterNode ).getColumn(),
|
delimiterNode.getColumn(),
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
parameter.setHqlParameterSpecification( paramSpec );
|
parameter.setHqlParameterSpecification( paramSpec );
|
||||||
|
|
|
@ -123,6 +123,11 @@ public class WithClauseTest extends FunctionalTestCase {
|
||||||
.list();
|
.list();
|
||||||
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
|
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();
|
txn.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue