英文:
QueryDSL: CaseBuilder Ambiguous method call and unexpected AST node
问题
我的项目使用的是springBoot版本2.5.7和querydsl版本5.0.0。
在一些代码中有如下部分:
.or(
Expressions.cases()
.when(intervalTo.isNotNull())
.then(
enablePath
.after(intervalFrom)
.and(enablePath.before(intervalTo))
)
.otherwise(
enablePath.after(intervalFrom)
)
);
-
在 .then 表达式中,我遇到了编译错误 "Ambiguous method call"(方法调用不明确)。(同时存在 then (Predicate) 和 then (ComparableExpression
) 方法) -
在将参数转换为 Predicate 后,我遇到了以下错误:
<AST>:6:588: 预期外的AST节点: case antlr.NoViableAltException:
预期外的AST节点: case at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2174)
at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2119)
at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2094)
at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:832)
at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:626)
我犯了什么错误?提前感谢。
英文:
My project with springBootVersion 2.5.7, querydsl 5.0.0
have some code:
.or(
Expressions.cases()
.when(intervalTo.isNotNull())
.then(
enablePath
.after(intervalFrom)
.and(enablePath.before(intervalTo))
)
.otherwise(
enablePath.after(intervalFrom)
)
);
- in .then expression i have compile error with Ambiguous method call.
(Both then (Predicate) and then (ComparableExpression<Boolean>)) - after casting arguments to Predicate i have error:
> <AST>:6:588: unexpected AST node: case antlr.NoViableAltException:
> unexpected AST node: case at
> org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2174)
> at
> org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2119)
> at
> org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2094)
> at
> org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:832)
> at
> org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:626)
What's my mistake? thank in advance
答案1
得分: 0
这是翻译好的部分:
这是我的失误,案例必须返回某个值:
.or(
Expressions.cases()
.when(intervalTo.isNotNull())
.then(
Expressions.cases().when(enablePath.after(intervalFrom)
.and(enablePath.before(intervalTo))
).then(1)
.otherwise(0)
)
.otherwise(
Expressions.cases().when(enablePath.after(intervalFrom)).then(1)
.otherwise(0)
).eq(1)
);
英文:
it was my fail, case must return some value:
.or(
Expressions.cases()
.when(intervalTo.isNotNull())
.then(
Expressions.cases().when(enablePath.after(intervalFrom)
.and(enablePath.before(intervalTo))
).then(1)
.otherwise(0)
)
.otherwise(
Expressions.cases().when(enablePath.after(intervalFrom)).then(1)
.otherwise(0)
).eq(1)
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论