Hi Scott,
The spec specifies the IN expression as:
in_expression ::=
state_field_path_expression [NOT] IN ( in_item {, in_item}* | subquery)
where in_item can be a parameter. So, in your case, you'd use a
parameter marker for each country:
@NamedQuery(name="findByCountry", query="SELECT c FROM Country c WHERE
c.id IN(?1, ?2, ?3)")
q.setParameter(1, "UK").setParameter(2, "US").setParameter(3, "France");
Also notice that the parameter in your example is declared and used in
different cases: "listId" and "listID".
Thanks,
-- markus.
Scott Oaks wrote:
> I'm trying to use a named query:
>
> @NamedQuery(name="findByCountry", query="SELECT c FROM Country c WHERE
> c.id IN(:listId)")
>
> I want to set the parameter to
>
> 'UK', 'US', 'France'
>
> But nothing I try works. If I do
> q.setParameter("listId", "US")
> then I get back the results with only the US (so I know the rest of the
> code is okay). But q.setParameter("listID", "'UK', 'US', 'France'")
> fails to retrieve anything, as does q.setParameter("listID", "UK, US,
> France") and q.setParameter("\"UK\", \"US\", \"France\").
>
> -Scott
>