This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I'm using openJPA native query defined in mapping file.
I've a select query where I'm trying to pass a List of values as input parameter to it using IN clause.
select... where... IN
SQL works , but when I use the same query in JPA with a positional parameter, It fails..
How to pass list of values to Query??
Here is the code.
When I execute this code, I'm getting
input Param :: '504152335','504152610','504180177','968718337'
Results size:: 0
With NO exception , no results.
I've treid removing single quotes in param, same output with 0 results.
i've tried making the input parametre as List<String>
When I run this Im getting following exception
Has anyone know about this issue?
Joined: Dec 16, 2004
Just in case, if somebody wants to know,
JPA 1.0 specification doesn't support passing list of values to native queries as I read somewhere.
it works with JPQL.
For native queries we have 2 work aorunds.
1. make the native named query IN caluse have as many number of positional parameters as many you have them in list.
In my case,
It kind of limits the dynamic nature of list. But if it's a list of String values, you can have max. number of positional parameters in the query and set the required number of parameters in the code, and for the rest of the excess positional parameters set null string. It works!
2. go for dynamic native query.
Here the query is appended with the list of params.