I have found one
other post about this problem, but it had no replies. I'm hoping a better Subject will have better results.
I need to count the number of acknowledged and unacknowledged records that have data in a field.
The SQL query works:
Code:
select acknowledged, msgDate is null, count(*) from Record where company_id=27 group by acknowledged, msgDate is null
The HQL version My HQL query looks like this:
Code:
select acknowledged, msgDate is null, count(*) from Record where company=:comp group by acknowledged, msgDate is null
However, it fails with the following:
Code:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: is null
If I try to use an alias, I get:
Code:
select acknowledged, msgDate is null as hasMsg, count(*) from Record where company=:comp group by acknowledged, hasMsg
ERROR org.hibernate.hql.PARSER(1):33 - <AST>:0:0: unexpected AST node: is null
which is followed by a NullPointerException in HqlSqlWalker.setAlias().
If I try to use field numbers in the group by clause, I get :
Code:
select acknowledged, msgDate is null, count(*) from Record where company=:comp group by 1,2
Unknown column '2' in 'group statement'
I've tried sticking it in a subquery and in a "new Map", but I always get one of the errors mentioned above.
I can move it to the where clause and just execute it twice, but I don't want to make an extra trip to the DB, and IT SHOULD WORK, DARN IT! :-/
I'm using MySQL 5.0.37 and Hibernate 3.2.4.