Hibernate(HQL) 怪异的count()函数


近日发现HQL中, count()函数要求还比较严格,举例说:

1、count(1)报错
Hql代码
  1. <query name="getRecordCountById">   
  2.     select count(1) as recordCount from Km c   
  3.     where c.id=:id   
  4. </query>  



2、count(c.*)报错
Hql代码
  1. <query name="getRecordCountById">   
  2.     select count(c.*) as recordCount from Km c   
  3.     where c.id=:id   
  4. </query>  


3、count(*)正确
Hql代码
  1. <query name="getRecordCountById">   
  2.     select count(*) as recordCount from Km c   
  3.     where c.id=:id   
  4. </query>  

相关内容