Playing a bit with this problem i came to the conclusion that logical expressions (= > < ...) are probably not directly supported in HQL because they are not supported by Oracle and MS SQL dialects, while experience with MySQL can give the impression that this should be possible.
MySQL:
select 1+2: 3
select 1>2: 0
Oracle:
select 1+2 from dual: 3
select 1>2 from dual: ORA-00923 FROM keyword not found where expected
MS SQL:
select 1+2: 3
select 1>2: Incorrect syntax near '>'.
in HQL it would be useful to have support for such expressions.
One easy way to evaluate boolean expressions in the DBMS would be to write the SQL with
CASE WHEN logical_expression THEN 1 ELSE 0
like:
select CASE WHEN 1>2 THEN 1 ELSE 0
which is supported by all of the above SQL dialects
...but according to docs
http://www.hibernate.org/hib_docs/v3/re ... xpressions
and grammar
http://hibernate.cvs.sourceforge.net/hi ... mmar/hql.g
case...when...then...else...end construct is only possible in the
where condition of HQL.
Easy fix would be to fix grammar to allow case...when in select part of HQL because it can be easy transcribed to SQL (valid in all SQL92 compliant SQL dialects).
More advanced fix would be to detect logical expressions in the select part of HQL and translate them into "case when logical_expression then 1 else 0 end".