gpt4 book ai didi

java - 转换查询时的 hibernate.QueryException

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

我有一个正在尝试执行的 HQL 查询,但我不断收到 QueryException。

我的查询是

SELECT a FROM (SELECT MAX(m.version) maxVersionOp, m.codoperacion codOp FROM ConsumoMe m WHERE m.codoperacion  IN ('MEL101','MEL102') AND m.horizontetemporal IN('PM') GROUP BY m.codoperacion), ConsumoMe a WHERE codOp = a.codoperacion AND maxVersionOp = a.version AND a.fechaBajaLogica IS NULL

我得到的异常是:

org.hibernate.QueryException: in expected: SELECT [SELECT a FROM (SELECT MAX(m.version) maxVersionOp, m.codoperacion codOp FROM es.enagas.siomprog.entities.ConsumoMe m WHERE m.codoperacion  IN ('MEL101','MEL102') AND m.horizontetemporal IN('PM') GROUP BY m.codoperacion), es.enagas.siomprog.entities.ConsumoMe a WHERE codOp = a.codoperacion AND maxVersionOp = a.version AND a.fechaBajaLogica IS NULL]

如果我剪切内部选择并尝试执行它:

SELECT MAX(m.version) maxVersionOp, m.codoperacion codOp FROM ConsumoMe m WHERE m.horizontetemporal IN('PM') AND (m.codoperacion = 'MEL101' OR m.codoperacion = 'MEL102') GROUP BY m.codoperacion

然后我得到了类似的异常:

org.hibernate.QueryException: , expected in SELECT [SELECT MAX(m.version) maxVersionOp, m.codoperacion codOp FROM es.enagas.siomprog.entities.ConsumoMe m WHERE m.horizontetemporal IN('PM') AND (m.codoperacion = 'MEL101' OR m.codoperacion = 'MEL102') GROUP BY m.codoperacion]

如果我运行 SQL 等效查询,我会得到有效的结果。此外,那些错误消息“,expected in SELECT”并不是很有帮助。知道可能是什么问题吗?

最佳答案

我在 SQL 中看到多个错误

m.codoperacion codOp --> m.codoperacion 作为 codOp

AND m.horizo​​ntetemporal IN('PM') AND GROUP BY m.codoperacion --> 不应该有 AND

AND m.horizontetemporal IN('PM') GROUP BY m.codoperacion

关于java - 转换查询时的 hibernate.QueryException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17348531/

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