【发布时间】:2020-10-12 21:07:09
【问题描述】:
在 QueryDSL 谓词组合方面需要帮助 - 如何编写 QueryDSL 谓词以使用 && 运算符比较两个数组(查找两个数组之间的任何 UUID 匹配项):
select '{e48f54d5-9845-4987-a53d-e0ecfe3dbb43}'::uuid[] && '{e48f54d5-9845-4987-a53d-e0ecfe3dbb43,4e9a43f2-cb23-4f1b-9f7f-c09687d97570}'::uuid[];
使用: 蟑螂 - v20.1.7, QueryDSL - v4.3.1
尝试了以下方法:
private BooleanBuilder createPredicates(QPlayer player, List<UUID> otherUuids) {
predicates.and(player.listOfUuids.any().in(otherUuids)); // player.listOfUuids is type of ListPath<java.util.UUID, ComparablePath<java.util.UUID>>
return predicates;
}
但它会引发异常:
java.lang.IllegalStateException: name property not available for path of type COLLECTION_ANY. Use getElement() to access the generic path element.
还尝试像这样创建booleanTemplate:
predicates.and(Expressions.booleanTemplate("{0} && '{{1}}'::uuid[]", player.listOfUuids, StringUtils.join(",", otherUuids)));
它返回这样一个SQL:
select ... where player.business_unit_ids && '{$1}'::uuid[]
但是执行它会引发异常:
io.r2dbc.postgresql.ExceptionFactory$PostgresqlNonTransientResourceException: [08P01] received too many type hints: 1 vs 0 placeholders in query
因为它解释了额外的 '{' 和 '}' 需要用来将其包装在 uuid 数组中作为另一个占位符。而且它也不尊重特殊符号转义或unicode。
有没有想过如何使用 QueryDSL 实现两个数组比较?
【问题讨论】:
标签: spring-boot querydsl cockroachdb spring-data-r2dbc