Skip to content

Commit

Permalink
HHH-2045 - HQL empty IN list
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-antoniak authored and brmeyer committed Feb 19, 2013
1 parent a44cc30 commit f4b45eb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions hibernate-core/src/main/antlr/hql.g
Expand Up @@ -758,6 +758,7 @@ collectionExpr
compoundExpr
: collectionExpr
| path
| { LA(1) == OPEN && LA(2) == CLOSE }? OPEN! CLOSE!
| (OPEN! ( (expression (COMMA! expression)*) | subQuery ) CLOSE!)
| parameter
;
Expand Down
Expand Up @@ -79,7 +79,9 @@ public void initialize() throws SemanticException {
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 );
Expand All @@ -96,7 +98,7 @@ public void initialize() throws SemanticException {
* 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;
}
Expand Down
Expand Up @@ -49,6 +49,7 @@
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;
Expand Down Expand Up @@ -77,6 +78,7 @@
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;
Expand Down Expand Up @@ -485,6 +487,33 @@ public void testPaginationWithPolymorphicQuery() {
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();
Expand Down
Expand Up @@ -245,7 +245,7 @@ public void testCollectionJoinsInSubselect() {
}

@Test
@FailureExpected( jiraKey = "N/A" )
@TestForIssue( jiraKey = "HHH-2045" )
public void testEmptyInList() {
assertTranslation( "select a from Animal a where a.description in ()" );
}
Expand Down

0 comments on commit f4b45eb

Please sign in to comment.