Search code examples
javajpakotlinsyntaxhibernate-criteria

Is there a way to pass a jpa predicate array to the criteriabuilder IN KOTLIN?


The solution proposed in: https://stackoverflow.com/a/11138229/1270045 works pretty fine in java but i am in kotlin. How can that be done here that i pass a predicate array to the criteria builder written in kotlin?

So its about writing this in kotlin that i can be passed on:

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

My example code:

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(???))

Solution

  • Thanks to marstran for your help that solved it:

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