gpt4 book ai didi

hibernate - JPA/JPQL : AS identifier disallowed in SELECT clause

转载 作者:行者123 更新时间:2023-12-05 05:28:21 26 4
gpt4 key购买 nike

我有一个非常复杂的 JPQL 查询表单

  SELECT NEW com.domain.project.view.StandingsStatLine(
ro.id AS rid
, cl.name AS team
, te.ordinalNbr + 1 AS nr
, pa.wasWithdrawn AS wd

, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END) AS g
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore > sca.finalScore THEN 1 ELSE 0 END) AS w
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore < sca.finalScore THEN 1 ELSE 0 END) AS l
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 20 AND sca.finalScore = 0 THEN 1 ELSE 0 END) AS wbr
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 0 AND sca.finalScore = 20 THEN 1 ELSE 0 END) AS lbr
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 0 AND sca.finalScore = 0 THEN 1 ELSE 0 END) AS blbr

, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore > sca.finalScore THEN 1 ELSE 0 END)
+ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END)
- SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 0 AND sca.finalScore = 20 THEN 1 ELSE 0 END) AS rp
, CASE WHEN ( SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore > sca.finalScore THEN 1 ELSE 0 END)
+ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END)
- SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 0 AND sca.finalScore = 20 THEN 1 ELSE 0 END)
- SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END))
/ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1.0 ELSE 0.0 END) >= 0.0
THEN (( SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore > sca.finalScore THEN 1 ELSE 0 END)
+ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END)
- SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore = 0 AND sca.finalScore = 20 THEN 1 ELSE 0 END)
- SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END))
/ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1.0 ELSE 0.0 END))
ELSE 0.0 END AS nrp
, CASE WHEN SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END) > 0
THEN (SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore > sca.finalScore THEN 1.0 ELSE 0.0 END)
/ SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN 1 ELSE 0 END))
ELSE NULL END AS wperc

, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore IS NOT NULL THEN scf.finalScore ELSE 0 END) AS ptsf
, SUM(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND sca.finalScore IS NOT NULL THEN sca.finalScore ELSE 0 END) AS ptsa

, MAX(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore NOT IN (0, 20) THEN scf.finalScore ELSE NULL END) AS hi
, MAX(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore NOT IN (0, 20) THEN scf.game.id ELSE NULL END) AS higid
, MIN(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore NOT IN (0, 20) THEN scf.finalScore ELSE NULL END) AS lo
, MIN(CASE WHEN paf.wasWithdrawn = FALSE AND paa.wasWithdrawn = FALSE AND scf.finalScore NOT IN (0, 20) THEN scf.game.id ELSE NULL END) AS logid
)
FROM Club cl
JOIN cl.teams te
JOIN te.rosters ro
JOIN ro.season se
JOIN ro.participations pa
JOIN pa.group gr
JOIN gr.round rd
JOIN rd.subCompetition sc
JOIN sc.competition cn
JOIN gr.games ga
JOIN ga.scores scf
JOIN ga.scores sca
JOIN scf.roster rof
JOIN sca.roster roa
JOIN rof.participations paf
JOIN roa.participations paa
WHERE ...
GROUP BY ...
ORDER BY pa.wasWithdrawn, nrp DESC, w DESC, lbr, g DESC, cl.shorthand

使用 Hibernate 4.x 运行它没有问题,但是 Eclipse Dali 在构造函数表达式的几乎每一行上都显示 JPQL 错误。删除 ... AS <identifier>摆脱这些错误。

我查看了 JPQL BNF http://en.wikibooks.org/wiki/Java_Persistence/JPQL_BNF在这里,但我找不到 AS在 SELECT 子句层次结构中。

问题:

这是 Hibernate 特定的语法吗?

为什么 JPQL 不支持这个?

有时表达式会变得非常复杂,我想通过 AS 记录表达式的实际含义。子句,特别是考虑到 JPQL 没有注释功能。这是 JPQL 恕我直言的真正缺陷。

此外,Hibernate 允许我引用这些 AS es 在 ORDER BY子句,它允许我重用上面的复杂语句。

也许我的表达方式可以缩短,但在其他情况/项目中,复杂性仍然很高。

谢谢

最佳答案

找到了。

根据位于 http://en.wikibooks.org/wiki/Java_Persistence/JPQL_BNF#New_in_JPA_2.0 的 JPQL BNF JPA 2.0 应该支持这一点。请注意,倒数第二个示例。

这几乎回答了为什么 Eclipse Dali 显示 JPQL 验证错误的原始问题。看来是大理的问题。

关于hibernate - JPA/JPQL : AS identifier disallowed in SELECT clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11807738/

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