"not in" clause occurs error in hibernate #516

Closed
mathicalee opened this Issue Oct 7, 2013 · 10 comments

Comments

Projects
None yet
4 participants
@mathicalee

querydsl-core: 3.2.3
hibernate-core: 4.2.6.Final

A query generated with notIn method looks like follows:

not (field in ?1)

but it seems that hibernate tries to parse the parentheses into a vector, therefore in my opinion, it should look like:

field not in ?1

in order to be excepted by hibernate.

I'm a beginner in querydsl and hibernate. Could someone help me out?

timowest added a commit that referenced this issue Oct 7, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 7, 2013

Member

Do you get an Exception?

Member

timowest commented Oct 7, 2013

Do you get an Exception?

@buechele

This comment has been minimized.

Show comment
Hide comment
@buechele

buechele Oct 8, 2013

I can confirm that there is an issue.

Example:

    public long testNotIn(Collection<Long> i) {       
        JPAQuery jpaQuery = getQueryFactory().createJPAQuery().from(QXXX.xxx).where(QXXX.xxx.id.notIn(i));       
        return jpaQuery.count();
    }

causes:

12:08:36,062 ERROR ErrorCounter:54 [main] - <AST>:0:0: unexpected AST node: {vector}
12:08:36,068 ERROR ErrorCounter:50 [main] - <AST>:0:0: unexpected AST node: {vector}
antlr.NoViableAltException: unexpected AST node: {vector}
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2051) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:794) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:595) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1261) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:287) [hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:311) [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at com.sun.proxy.$Proxy35.getSingleResult(Unknown Source) [na:na]
    at com.mysema.query.jpa.impl.AbstractJPAQuery.count(AbstractJPAQuery.java:84) [querydsl-jpa-3.2.3.jar:na]
[...]

buechele commented Oct 8, 2013

I can confirm that there is an issue.

Example:

    public long testNotIn(Collection<Long> i) {       
        JPAQuery jpaQuery = getQueryFactory().createJPAQuery().from(QXXX.xxx).where(QXXX.xxx.id.notIn(i));       
        return jpaQuery.count();
    }

causes:

12:08:36,062 ERROR ErrorCounter:54 [main] - <AST>:0:0: unexpected AST node: {vector}
12:08:36,068 ERROR ErrorCounter:50 [main] - <AST>:0:0: unexpected AST node: {vector}
antlr.NoViableAltException: unexpected AST node: {vector}
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2051) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:794) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:595) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1261) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:287) [hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:311) [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at com.sun.proxy.$Proxy35.getSingleResult(Unknown Source) [na:na]
    at com.mysema.query.jpa.impl.AbstractJPAQuery.count(AbstractJPAQuery.java:84) [querydsl-jpa-3.2.3.jar:na]
[...]
@mathicalee

This comment has been minimized.

Show comment
Hide comment
@mathicalee

mathicalee Oct 8, 2013

Thanks, that's the same Exception I've got.

Thanks, that's the same Exception I've got.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 8, 2013

Member

Could you confirm whether the given collection is empty?

Member

timowest commented Oct 8, 2013

Could you confirm whether the given collection is empty?

@buechele

This comment has been minimized.

Show comment
Hide comment
@buechele

buechele Oct 8, 2013

The given Collection is not empty. It contains 2 elements in my testcase.

With an empty collection I got:

15:36:00,504 ERROR ErrorCounter:54 [main] - line 3:26: unexpected token: )
15:36:00,510 ERROR ErrorCounter:50 [main] - line 3:26: unexpected token: )
antlr.NoViableAltException: unexpected token: )
    at org.hibernate.hql.internal.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:3104) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlBaseParser.inList(HqlBaseParser.java:2884) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
[...]

The first exception antlr.NoViableAltException: unexpected AST node: {vector} only occurs if you have more than one element in the collection.

buechele commented Oct 8, 2013

The given Collection is not empty. It contains 2 elements in my testcase.

With an empty collection I got:

15:36:00,504 ERROR ErrorCounter:54 [main] - line 3:26: unexpected token: )
15:36:00,510 ERROR ErrorCounter:50 [main] - line 3:26: unexpected token: )
antlr.NoViableAltException: unexpected token: )
    at org.hibernate.hql.internal.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:3104) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
    at org.hibernate.hql.internal.antlr.HqlBaseParser.inList(HqlBaseParser.java:2884) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
[...]

The first exception antlr.NoViableAltException: unexpected AST node: {vector} only occurs if you have more than one element in the collection.

@filipkokorevs

This comment has been minimized.

Show comment
Hide comment
@filipkokorevs

filipkokorevs Oct 8, 2013

I can reproduce the bug after upgrading to the version mentioned above.

I can reproduce the bug after upgrading to the version mentioned above.

timowest added a commit that referenced this issue Oct 8, 2013

timowest added a commit that referenced this issue Oct 8, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 9, 2013

Member

Could you try again with the latest SNAPSHOT from here https://oss.sonatype.org/content/repositories/snapshots/

Member

timowest commented Oct 9, 2013

Could you try again with the latest SNAPSHOT from here https://oss.sonatype.org/content/repositories/snapshots/

@mathicalee

This comment has been minimized.

Show comment
Hide comment
@mathicalee

mathicalee Oct 9, 2013

I did a test and it works. Thank you very much :)

I did a test and it works. Thank you very much :)

@buechele

This comment has been minimized.

Show comment
Hide comment
@buechele

buechele Oct 9, 2013

Yes, I have also tested it and it works now seamless.
I have used following SNAPSOT-dependencies for testing:
querydsl-jpa-3.2.4.BUILD-20131009.052743-4
querydsl-codegen-3.2.4.BUILD-20131009.051816-4
querydsl-core-3.2.4.BUILD-20131009.051620-5
querydsl-apt-3.2.4.BUILD-20131009.051942-4

buechele commented Oct 9, 2013

Yes, I have also tested it and it works now seamless.
I have used following SNAPSOT-dependencies for testing:
querydsl-jpa-3.2.4.BUILD-20131009.052743-4
querydsl-codegen-3.2.4.BUILD-20131009.051816-4
querydsl-core-3.2.4.BUILD-20131009.051620-5
querydsl-apt-3.2.4.BUILD-20131009.051942-4

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 20, 2013

Member

Released in 3.2.4

Member

timowest commented Oct 20, 2013

Released in 3.2.4

@timowest timowest closed this Oct 20, 2013

@timowest timowest added this to the 3.2.4 milestone Apr 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment