在hibernate聚合函数中使用函数作为参数 [英] Using functions as arguments in hibernate aggregation functions
问题描述
我想在HQL中执行以下查询:
I would like to perform the following query in HQL:
select count(distinct year(foo.date)) from Foo foo
然而,这会导致以下异常:
However, this results in the following exception:
org.hibernate.hql.ast.QuerySyntaxException:
expect CLOSE,found'('near line
1,column 27
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 27
看来hibernate不允许使用函数作为它的聚合函数的参数。是否有任何方法可以获得所需的结果?
It seems that hibernate does not allow using functions as arguments to its aggregation functions. Is there any way to get the required result?
推荐答案
- 从每个日期开始的一年
起初听起来无效,但它只是一个附加的O(n),我猜N是那么大。
At first it sounds ineffective, but then it's just an additional O(n), and I guess N isn't that big.
另一种方法是使用本地SQL查询。
Another way is to use a native SQL query.
这篇关于在hibernate聚合函数中使用函数作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!