Issue Type: Bug Bug
Affects Versions: 4.0.1
Assignee: Unassigned
Created: 25/Jun/12 7:36 AM
Description:

I have the following JPQL:

SELECT ed
      FROM ExternalDocument ed
        LEFT JOIN FETCH ed.documentType dt
        JOIN FETCH ed.company co
      WHERE co IN :companies AND (dt IS NULL OR dt IN :docTypes)
      ORDER BY ed.fileName

Since AND binds tighter than OR the parentheses are mandatory. (:companies and :docTypes are both java.util.List)

However, Hibernate fails with:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} [SELECT ed FROM de.company.project.model.ExternalDocument ed LEFT JOIN FETCH ed.documentType dt JOIN FETCH ed.company co WHERE co IN (:companies0_, :companies1_, :companies2_) AND (dt IS NULL OR dt IN :docTypes0_, :docTypes1_, :docTypes2_, :docTypes3_) ORDER BY ed.fileName]
	at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
	at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
	at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:255)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
	at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1107)
	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
	at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252)
	... 154 more

You can see that the second IN :docTypes0_, :docTypes1_, :docTypes2_, :docTypes3_ expression is missing the parentheses.

Environment: JBoss AS 7.1.1.Final, Hibernate 4.0.1.Final
Project: Hibernate ORM
Priority: Minor Minor
Reporter: Karsten Wutzke
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira