gpt4 book ai didi

java - 使用 HQL 从(选择...)中选择

转载 作者:行者123 更新时间:2023-12-01 12:13:25 27 4
gpt4 key购买 nike

如何在 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]

最佳答案

这不是标准的 HQL。您使用的是 native SQL。因此,在代码中使用 createSQLQuery 代替 createQuery 进行查询。

关于java - 使用 HQL 从(选择...)中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27145331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com