如何在Hibernate HQL中编写以下内容?
SELECT *
FROM (SELECT *
FROM example_table
ORDER BY table_date DESC) AS oo
GROUP BY table_date;
HQL:
SELECT o
FROM (SELECT op
FROM example_table op
ORDER BY table_date DESC) o
GROUP BY table_date DESC;
我得到的错误
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token:
( near line 1, column 15 [SELECT o FROM (SELECT op FROM za.co.paygate.intranet.database.model.FinTrans op WHERE clientId = :clientId AND finTransDate BETWEEN :monthStart AND :monthEnd ORDER BY finTransDate DESC) o GROUP BY clientTermId];
nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token:
( near line 1, column 15 [SELECT o FROM (SELECT op FROM za.co.paygate.intranet.database.model.FinTrans op WHERE clientId = :clientId AND finTransDate BETWEEN :monthStart AND :monthEnd ORDER BY finTransDate DESC) o GROUP BY clientTermId]
答案 0 :(得分:1)
这不是标准的HQL。您使用的是本机SQL。因此,在代码中使用createSQLQuery进行查询而不是createQuery。