我有一个正在尝试执行的 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 等效查询,我会得到有效的结果。此外,那些错误消息“,在 SELECT 中预期”不是很有帮助。知道可能是什么问题吗?