IN clause in @NamedNativeQuery [message #646278] |
Wed, 22 December 2010 23:29  |
Eclipse User |
|
|
|
Dear All,
I want to use @NamedNativeQuery for one of my query which is quite complex to write as @NamedQuery and it contains IN clause where we need to specify parameters dynamically.
When i wrote query in my code like:
SELECT [COLUMNS] FROM TABLE WHERE COLUMN IN ('A','B','C')
it works perfectly, but when i try to put this query inside my entity object as:
@NamedNativeQuery (name="XXX",query="SELECT [COLUMNS] FROM TABLE WHERE COLUMN IN ?1")
it doesn't work.
I have used IN clause as mentioned above in JPQLs using @NamedQuery and it works fine but when it comes to @NamedNativeQuery it stops working.
So i assume eclipselink doesn't support parameterized "IN clause" in case of @NamedNativeQuery. Is it TRUE?
|
|
|
|
Re: IN clause in @NamedNativeQuery [message #647083 is a reply to message #646377] |
Tue, 04 January 2011 09:35   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.08573 seconds