HHH-2045 - HQL empty IN list

This commit is contained in:
Lukasz Antoniak 2013-02-01 15:17:30 +01:00 committed by Brett Meyer
parent a44cc3097a
commit f4b45eb5a9
4 changed files with 35 additions and 3 deletions

View File

@ -758,6 +758,7 @@ collectionExpr
compoundExpr
: collectionExpr
| path
| { LA(1) == OPEN && LA(2) == CLOSE }? OPEN! CLOSE!
| (OPEN! ( (expression (COMMA! expression)*) | subQuery ) CLOSE!)
| parameter
;

View File

@ -79,7 +79,9 @@ public class InLogicOperatorNode extends BinaryLogicOperatorNode implements Bina
if ( !isNodeAcceptable( rhsNode ) )
return;
int rhsColumnSpan = 0;
if ( rhsNode.getType() == HqlTokenTypes.VECTOR_EXPR ) {
if ( rhsNode == null ) {
return; // early exit for empty IN list
} else if ( rhsNode.getType() == HqlTokenTypes.VECTOR_EXPR ) {
rhsColumnSpan = rhsNode.getNumberOfChildren();
} else {
Type rhsType = extractDataType( rhsNode );
@ -96,7 +98,7 @@ public class InLogicOperatorNode extends BinaryLogicOperatorNode implements Bina
* this is possible for parameter lists and explicit lists. It is completely unreasonable for sub-queries.
*/
private boolean isNodeAcceptable( Node rhsNode ) {
return rhsNode instanceof LiteralNode
return rhsNode == null /* empty IN list */ || rhsNode instanceof LiteralNode
|| rhsNode instanceof ParameterNode
|| rhsNode.getType() == HqlTokenTypes.VECTOR_EXPR;
}

View File

@ -49,6 +49,7 @@ import org.hibernate.TypeMismatchException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.MySQLDialect;
@ -77,6 +78,7 @@ import org.hibernate.test.cid.Order;
import org.hibernate.test.cid.Product;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
@ -485,6 +487,33 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-2045" )
@RequiresDialect( H2Dialect.class )
public void testEmptyInList() {
Session session = openSession();
session.beginTransaction();
Human human = new Human();
human.setName( new Name( "Lukasz", null, "Antoniak" ) );
human.setNickName( "NONE" );
session.save( human );
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
List results = session.createQuery( "from Human h where h.nickName in ()" ).list();
assertEquals( 0, results.size() );
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
session.delete( human );
session.getTransaction().commit();
session.close();
}
@Test
public void testComponentNullnessChecks() {
Session s = openSession();

View File

@ -245,7 +245,7 @@ public class HQLTest extends QueryTranslatorTestCase {
}
@Test
@FailureExpected( jiraKey = "N/A" )
@TestForIssue( jiraKey = "HHH-2045" )
public void testEmptyInList() {
assertTranslation( "select a from Animal a where a.description in ()" );
}