evaluateBuilder selectCase在聚合函数中抛出QuerySyntaxException

时间:2017-11-20 14:47:15

标签: hibernate criteria-api jpa-2.1

我想在聚合函数中做一个select case,但它抛出QuerySyntaxException

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: case near line 1, column 125 : [select new com.dev.entity.User(generatedAlias0.id, generatedAlias0.name, generatedAlias0.date, generatedAlias0.mode, count(case when generatedAlias0.id=:param2 then :param3 else :param4 end)) from com.renault.dev.User as generatedAlias0]

如果无法识别case函数:/

有标准查询

Expression<String> idCountCase = builder.<String>selectCase().when(builder.equal(userRoot.get(User_.id), "id01"), "EXISTS").otherwise("NOT EXISTS");
Expression<Long> idCount = builder.count(idCountCase);
criteriaQuery.multiselect(userRoot.get(User_.id), userRoot.get(User_.name), userRoot.get(User_.date), userRoot.get(User_.mode), idCount);

有什么建议吗?
非常感谢你

1 个答案:

答案 0 :(得分:0)

解决。我刚刚更新了Hibernate版本,现在可以使用了。我想在以前的版本中不支持聚合函数的条件......