0

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 [(].
cmd
  • 11,622
  • 7
  • 51
  • 61
Kevin
  • 4,070
  • 4
  • 45
  • 67
  • 1
    clearly that is not valid JPQL, so no JPA implementation would "support" it without (non-portable) vendor extensions. JPQL does allow "FUNCTION" where you could put your FIELD thing in (and that is portable JPQL) – DataNucleus Jan 09 '14 at 15:23

1 Answers1

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.

cmd
  • 11,622
  • 7
  • 51
  • 61