1

我是新来的冬眠。我想在我的休眠 sql 查询中使用关键字,如下所示:

 select from Store where storeName like 'a%' having productCount >1

这里 Store 与 store 表映射,storeName 与 store 表的 store_name 映射,productCount 与 store 表的 product_count 映射。

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

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

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

4

2 回答 2

2

您只能HAVING与 一起使用GROUP BY。没有 GROUP BY 没有意义。在您的示例中,缺少 GROUP BY 子句。

也许你的意思是这个(如果你想计算行数)

from Store where storeName like 'a%' group by storeName having count(*) >1

或者这个(如果有一个映射成员变量名称 productCount 的列)

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

(PS 在您的示例中更好地使用from而不是select- 但这与您的错误没有任何关系。)

于 2012-11-07T12:52:59.673 回答
0

你不能拥有,两者都应该像

 from Store where storeName like 'a%' and productCount >1
于 2012-11-07T11:22:41.210 回答