openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: OpenJPA1.2.2 - NativeQuery - IN clause
Date Tue, 01 Sep 2009 03:13:30 GMT
Hi,
This is not my area of expertise.  But since ?1 refers to a single
parameter, and you mentioned that "A" is a valid value with successful
results, I would try something like " 'A', 'B' ".  Another alternative would
be to list additional parameters, ie. ?1, ?2, ?3, etc.  But, of course, this
would not be as flexible.  Maybe somebody has more direct experience with
this usage...

Kevin

On Mon, Aug 31, 2009 at 5:28 PM, HaricotBean <bill@wilkins-family.org.uk>wrote:

>
> Which type is NativeQuery expecting for a parameter that maps to a IN
> clause?
> Through trial and error I found that Collections cause an error to be throw
> and Arrays execute but return no results.  However if I pass a single
> String
> value it works...
>
> @NamedNativeQuery(name = "Entity.mostRefersType", query = "select
> count(e.eid), e.* from Entity e, Property p where e.eid=p.refersTo and
> p.type IN ( ?1 ) group by e.eid order by count(e.eid) desc;",
> resultSetMapping = "MostUsedResults"),
>
> Surprisingly (to me at least) the following has been my observation:
>
> query.setParameter(1, "A"); // successful
> query.setParameter(1, {"A","B"}); // executes but fails to match
> Collection<String> set = new ArraySet(); set.add("A)";
> query.setParameter(1, set); // throws invalid parameter exception on
> execute
>
> Does anyone have any clues as to what the right approach might be to use a
> named query. The alternative is to build a string representation of the sql
> statement but I would like to find the answer.
>
> Regards ...
>
>
> --
> View this message in context:
> http://n2.nabble.com/OpenJPA1-2-2-NativeQuery-IN-clause-tp3556433p3556433.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message