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/trunk@16668 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
35a28509f2
commit
1a3d59029f
|
@ -33,6 +33,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -66,7 +67,6 @@ import org.hibernate.hql.ast.tree.RestrictableStatement;
|
|||
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;
|
||||
|
@ -347,9 +347,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
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 {
|
||||
withClause( hqlWithNode );
|
||||
AST hqlSqlWithNode = returnAST;
|
||||
|
@ -359,14 +357,22 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
WithClauseVisitor visitor = new WithClauseVisitor( fromElement );
|
||||
NodeTraverser traverser = new NodeTraverser( visitor );
|
||||
traverser.traverseDepthFirst( hqlSqlWithNode );
|
||||
|
||||
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;
|
||||
|
@ -854,8 +860,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
ParameterNode parameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
|
||||
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
|
||||
( ( Node ) inputNode ).getLine(),
|
||||
( ( Node ) inputNode ).getColumn(),
|
||||
inputNode.getLine(),
|
||||
inputNode.getColumn(),
|
||||
positionalParameterCount++
|
||||
);
|
||||
parameter.setHqlParameterSpecification( paramSpec );
|
||||
|
@ -873,8 +879,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
parameter.setText( "?" );
|
||||
|
||||
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
|
||||
( ( Node ) delimiterNode ).getLine(),
|
||||
( ( Node ) delimiterNode ).getColumn(),
|
||||
delimiterNode.getLine(),
|
||||
delimiterNode.getColumn(),
|
||||
name
|
||||
);
|
||||
parameter.setHqlParameterSpecification( paramSpec );
|
||||
|
@ -949,9 +955,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -123,6 +123,11 @@ public class WithClauseTest extends FunctionalTestCase {
|
|||
.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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue