Reputation: 45
How do you write the following in 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;
The error I'm getting
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]
Upvotes: 0
Views: 1453
Reputation: 527
This is not standard HQL. What you are using is native SQL. So createSQLQuery for quering instead of createQuery in you code.
Upvotes: 1