ANKIT PRASAD
ANKIT PRASAD

Reputation: 88

How to call a function using JPA Criteria API?

I am creating a specification which returns the records for the ids provided by the db function GET_RECORD_IDS. I am providing my code snippet below-

return ((root, query, criteriaBuilder) -> criteriaBuilder.and(root.get("id").in(
criteriaBuilder.function("GET_RECORD_IDS", List.class, criteriaBuilder.literal(str))))

But this code results in the error set-returning functions are not allowed in WHERE. How do I make this work?

Upvotes: 1

Views: 2574

Answers (1)

ANKIT PRASAD
ANKIT PRASAD

Reputation: 88

I found out that the following code makes it work-

return ((root, query, criteriaBuilder) -> criteriaBuilder.and(root.get("id").in(
criteriaBuilder.function("select id from GET_RECORD_IDS", List.class, criteriaBuilder.literal(str))))

Upvotes: 1

Related Questions