The problem is that the HQL query parser can not handle the subquery within a case when statement. Parsing of the following query fails
SELECT CASE WHEN d.id IS NOT NULL THEN (SELECT COUNT(p.id) FROM Person p) ELSE 0 END FROM Document d