Many HQL queries which use the HQL in operation (element of set or list), can cause a syntactically incorrect HQL query. Syntax error are then reported through Tomcat. An example query is:

from Issue as i
where ~u in i._project._members

In which Issue is an entity, u is a User and i._project._members refers to a set of users.

Submitted by Sander Vermolen on 9 February 2010 at 14:25

On 12 February 2010 at 09:48 Sander Vermolen commented:

I found a work-around for this issue, that does not use inefficient code. A query using in can be rewritten to a query using two joins and a select. For example, the above query can be rewritten to:

select i from Issue as i
left join i._project._members as m
where m = ~u

Note that separating the joins, for example to add a condition on the project attributes, is not supported in the WebDSL syntax.


On 12 February 2010 at 09:54 Lennart Kats commented:

The problem here seems to be pretty printing of HQL queries before they are passed to Hibernate? Is it a lack of parenthization or are the pretty printer rules b0rked?


On 2 March 2011 at 09:12 Christoffer Gersen commented:

You can also use the elements() function like this:

from Issue as i
where ~u in elements(i._project._members)

This will generate a subquery fetching the ids from the join table. You can also use indices() instead to select the indices from the join table, which may be of use in other situations.

You also get exceptions for queries like:

from Issue as i
where i._project in (~projects)

In this case I got org.hibernate.PropertyAccessException and java.lang.IllegalArgumentException. The problem here is that WebDSL uses setParameter() instead of setParameterList() to bind the variable “projects”, which is a list of project objects. I have not found a way around this issue.


On 19 April 2011 at 09:11 Zef Hemel removed tag @zefhemel

Log in to post comments