有没有一种方法可以将JPA谓词数组传递给criteriabuilder IN KOTLIN?

时间:2019-01-23 11:18:31

标签: java jpa kotlin syntax hibernate-criteria

提出的解决方案: https://stackoverflow.com/a/11138229/1270045 在java中工作正常,但我在kotlin中。 我如何将谓词数组传递给用kotlin编写的条件构建器,该怎么做?

因此,关于用kotlin编写此内容,我可以继续下去:

cq.select(customer).where(predicates.toArray(new Predicate[]{}));

我的示例代码:

val predicates = mutableListOf<Predicate>()
if (XYZ != null) {
    val XYZPath = element.get<Long>("XYZ")
    predicates.add(criteriaBuilder.equal(XYZPath, XYZ))
}
criteriaQuery.select(element)
    .where(criteriaBuilder.or(???))

1 个答案:

答案 0 :(得分:2)

感谢marstran为您解决的帮助:

criteriaQuery.select(element)
    .where(criteriaBuilder.or(*predicates.toTypedArray()))