gpt4 book ai didi

java - 期待关闭,在第 1 行附近发现 'WHEN' 异常?如何在 HIbernate 中摆脱它

转载 作者:行者123 更新时间:2023-11-29 21:49:00 25 4
gpt4 key购买 nike

我在 Java Hibernate 的查询中使用 WHEN CASE 条件。该查询在 MySQL 工作台中工作正常,但在 Java 控制台中出现此异常。

:org.hibernate.hql.internal.ast.QuerySyntaxException: expecting CLOSE, found 'WHEN' near line 1.

这是我的查询,

StringBuffer hql = new StringBuffer();


hql.append(" SELECT ");
hql.append(" v.year,");
hql.append(" v.number,");
hql.append(" ap.property,");
hql.append(" CASE");
hql.append(" WHEN ap.id = 1 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 2 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 3 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 4 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 5 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 6 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 7 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 8 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 9 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 10 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 11 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 12 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 13 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 14 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 15 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 16 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 17 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 18 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 19 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 20 THEN AVG(v.Month101)");
hql.append(" WHEN ap.id = 21 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 22 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 23 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 24 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 25 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 26 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 27 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 28 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 29 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 30 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 31 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 32 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 33 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 34 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 35 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 36 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 37 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 38 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 39 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 40 THEN SUM(v.Month101)");
hql.append(" WHEN ap.id = 41 THEN SUM(v.Month101)");
hql.append(" END AS jan,");
hql.append(" FROM");
hql.append(" table1 v,");
hql.append(" table2 ap");
hql.append(" WHERE");
hql.append(" v.number=01");
hql.append(" AND v.Id = ap.id");
hql.append(" AND v.year =2015");
hql.append(" GROUP BY ap.property");
hql.append(" ORDER BY v.Id");

我已经有这个条件 12 个月了,语法有什么问题吗?有人能解释一下吗?

最佳答案

我认为由于 as END AS jan 后面有一个逗号而出现语法错误

hql.append(" END AS jan,");
hql.append(" FROM");

删除上面 jan 之后的逗号并再次检查 - 我想它会起作用。

关于java - 期待关闭,在第 1 行附近发现 'WHEN' 异常?如何在 HIbernate 中摆脱它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33840297/

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