在hibernate hsql中是否可以使用“have”?

在hibernate hsql中是否可以使用“have”?,hibernate,Hibernate,我刚开始冬眠。我想在hibernate sql查询中使用having关键字,如下所示: select from Store where storeName like 'a%' having productCount >1 这里,Store与Store表映射,storeName与Store表的Store\u名称映射,productCount与Store表的product\u计数映射 所有的映射工作正常。但当我运行此查询时,它返回以下错误: org.hibernate.hql.ast.Q

我刚开始冬眠。我想在hibernate sql查询中使用having关键字,如下所示:

 select from Store where storeName like 'a%' having productCount >1
这里,Store与Store表映射,storeName与Store表的Store\u名称映射,productCount与Store表的product\u计数映射

所有的映射工作正常。但当我运行此查询时,它返回以下错误:

 org.hibernate.hql.ast.QuerySyntaxException: unexpected token: having near line 1, column 43.

有人能帮我解决这个问题吗?

你不能拥有,两者都应该是什么样子

 from Store where storeName like 'a%' and productCount >1
您只能使用与GROUP BY一起使用。没有分组是没有意义的。在您的示例中,缺少GROUPBY子句

如果你想数数行,也许你是这个意思

from Store where storeName like 'a%' group by storeName having count(*) >1
或者,如果存在具有映射成员变量名productCount的列,则为

from Store where storeName like 'a%' and productCount >1

在你的例子中,最好使用from而不是select,但这与你的错误无关

我尝试了你的答案,但它再次显示了错误消息:org.hibernate.hql.ast.QuerySyntaxException:意外标记:第二个示例不正确-不使用group by是不可能的,也没有意义它不仅限于group by,还限于任何聚合函数