问题
MySQL supports queries such as:
SELECT id FROM users WHERE id IN(3,4,8,1) ORDER BY FIELD(id, 3,4,8,1);
Does EclipseLink support this query (without reverting to a native query)?
When I try the following:
Select id from User user where user.id in :ids ORDER BY FIELD(user.id, :ids)
I receive the error:
Syntax error parsing the query ... line 1, column 98: unexpected token [(].
回答1:
ORDER BY FIELD(field, :values)
is not supported by JPA (JQL) or EclipseLink.
JPA does provide a mechanism to execute native queries. You could create a native query to invoke a query similar to that in your description, however, it of course, would not be portable.
来源:https://stackoverflow.com/questions/21014679/does-eclipselink-support-order-by-fieldfield-values