Play! Framework Executing a JPA Request for a Range of Values ​​Using IN

I am trying to retrieve values ​​from a database using IN. I realized that I need to write a JPA request, for example

o.country IN (’UK’, ’US’, ’France’)  

so I tried to write a request

List result = Playlist.find("id in ?", values).fetch();  

Where values=set of integers

but it cannot compile at runtime

java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.Integer   

How to fix it?

Fixed

I also posted this in google groups and got an 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(); 
+3
source share
1 answer

I am not sure about some aspects of your question:

  • I don't know anything about the Playlist class and its methods.
  • What do you mean by "but does not compile at run time"? Can't compile or fail to complete it?

( , , ) :

Entity JPA: @NamedQuery(name = "findFoo", query = "select f from Foo f where f.state in :stateInList")

:

final Query query = this.entityManager.createNamedQuery("findFoo");
final Set<FooState> states = new HashSet<FooState>(Arrays.asList(FooState.STARTED, FooState.FAILED));
query.setParameter("stateInList", states);
final List<Foo> retval = query.getResultList();
return retval;

+2

All Articles