简单的连接语法不能正常工作

simple join syntax not properly working

我想显示按服务名称分组的历史记录数table

请注意,table 历史和服务之间没有关系,历史存储 activity 独立于其他 table

我已经测试了这个 sql 查询并且它 returns 预期结果:

select s.name, count(*) from history c
join service s
on c.code=s.code 
where c.state='INITIALE'
group by s.name

其实我想用jpql写的,我也是这样

 Query query =entityManager.createQuery(" select s.name, count(*) from  ServiceEntity s join"
                + " HistoryEntity c  "
                + " where c.code=s.code and c.state='INITIALE'"
                + " group by c.name order by c.name"
                );

我得到这个错误需要加入的路径!.... 无效路径:'c.code'...二元运算符的右侧操作数为空...子树意外结束

试试这个

Query query = entityManager.createQuery("select s.name, count(s) from  ServiceEntity s, HistoryEntity c "
                + " where c.code = s.code and c.state = 'INITIALE'"
                + " group by s.name order by s.name"
                );