QueryDSL: CaseBuilder模糊的方法调用和意外的AST节点

huangapple go评论58阅读模式
英文:

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)
            )
);
  1. .then 表达式中,我遇到了编译错误 "Ambiguous method call"(方法调用不明确)。(同时存在 then (Predicate) 和 then (ComparableExpression) 方法)

  2. 在将参数转换为 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)
			)
);
  1. in .then expression i have compile error with Ambiguous method call.
    (Both then (Predicate) and then (ComparableExpression&lt;Boolean&gt;))
  2. after casting arguments to Predicate i have error:

> &lt;AST&gt;: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)
);

huangapple
  • 本文由 发表于 2023年6月26日 12:33:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76553535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定