2012-11-07 38 views
1

我是新来的冬眠。我想使用具有关键字在我的休眠sql查询像:'有'可能在休眠hsql?

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

这里存储映射与存储表和STORENAME映射与存储表和productCount映射与存储表的PRODUCT_COUNT的STORE_NAME。

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

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

所以,任何人都可以帮我解决这个问题?

回答

0

你不能拥有和地方都应该像任何

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

我试着用你的答案,但它再次显示错误消息:org.hibe rnate.hql.ast.QuerySyntaxException:意外的令牌: – shiva

+0

第二个示例不正确 - 没有group by是不可能的,也没有意义) – Johanna

+0

与您同意.. –

2

只能连同GROUP BY使用HAVING。没有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 - 但这与你的错误没有任何关系。)

+1

它并不仅限于“group by”但对任何聚合函数 – enTropy