I have been trying to fetch values from database using IN. I realized that I need to write JPA query like
o.country IN (’UK’, ’US’, ’France’)
so I tried to write query
List result = Playlist.find("id in ?", values).fetch();
where values=set of integers
but it fails to compile on runtime
java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.Integer
How do I fix this?
Fixed
I also posted this on google groups and got the answer that seems to work
List<Integer> countries = (list of integers for ’UK’, ’US’, ’France’)
List result = Playlist.find("id in (:countries)").bind("countries",
countries).fetch();
I’m not alltogether sure about some aspects of your question:
Anyway here’s an (modified and thus unchecked) example from my codebase:
In an JPA Entity class:
@NamedQuery(name = "findFoo", query = "select f from Foo f where f.state in :stateInList")There query is used like so:
HTH