0

I want to write a jpa Predicate to get criteria query giving the same result as this HQL query:

from Profile P WHERE (:interests) in P.profileInterests

, where "interests" is a method parameter ( List of Strings ) and profileInterests is a field of Profile entity class (also List of Strings).

I still get ClassCastException.

T.Seroka
  • 13
  • 7
  • Use `root.get(profileInterests).in(interests)`. – Kirinya Jan 17 '18 at 17:08
  • You mean `predicates.add(root.get("profileInterests").in(interests))` ? I get `java.base/java.lang.String cannot be cast to java.base/java.util.List`when I apply that, and if I don't apply, just leave it blank, and create query with other predicates, like `predicates.add(builder.equal(root.get("city"), city )) `, it executes properly. – T.Seroka Jan 17 '18 at 17:18
  • No, you cannot use `IN` for collection IN collection, as per what the JPA spec says. Multiple clauses are needed for that –  Jan 17 '18 at 17:53
  • Possible duplicate of [JPA Criteria API IN expression Parameter list](https://stackoverflow.com/questions/10732970/jpa-criteria-api-in-expression-parameter-list) – Simon Martinelli Jan 17 '18 at 20:37

0 Answers0