|
|
Re: IN clause in @NamedNativeQuery [message #647083 is a reply to message #646377] |
Tue, 04 January 2011 14:35 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
I do not believe 328378 is related, as 328378 deals with JPQL queries but the first post mentions using NamedNativeQuery - straight SQL queries.
Can you please post the exception you are getting? My guess is you are attempting to pass in a collection to
@NamedNativeQuery (name="XXX",query="SELECT [COLUMNS] FROM TABLE WHERE COLUMN IN ?1")
for the ?1 parameter, where as in the working query you have each parameter defined individually as in ('A','B','C'). Please note that Native queries are passed to the database exactly as defined, so I would suggest instead using:
@NamedNativeQuery (name="XXX",query="SELECT [COLUMNS] FROM TABLE WHERE COLUMN IN(?1,?2,?3)")
and then passing a collection with 3 arguments.
Or, you can try a JPQL query:
@NamedQuery (name="XXX",query="SELECT [COLUMNS] FROM TABLE WHERE COLUMN IN(?1)")
JPQL processing will create the appropriate sql based on the number of arguments if a collection is used for the ?1 parameter.
Best Regards,
Chris
|
|
|
Re: IN clause in @NamedNativeQuery [message #647209 is a reply to message #647083] |
Wed, 05 January 2011 04:23 |
Sarkan Messages: 10 Registered: May 2010 |
Junior Member |
|
|
Hi Chris,
You're right the JPQL with parameter (IN ?1) works perfectly fine but in our case as i said the query is quite complex to be written as JPQL so we are using native query instead.
Now the problem with native query is we can not define (IN ?1) parameter as is does not work. And we dont have fixed number of parameters like 3 or so.
That's why we need one parameter (?1), which should accept collections otherwise we have make a comma separated string out of my collection and add it to the query dynamically .
I would appreciate If you have a better idea to share.
[Updated on: Wed, 05 January 2011 04:26] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02920 seconds