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 2ee27348d0
commit a89a9f33b2
4 changed files with 35 additions and 3 deletions

View File

@ -698,6 +698,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;
@ -76,6 +77,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;
@ -479,6 +481,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 ()" );
}