persistence@glassfish.java.net

Query IN Clause: Dynamic Number of Parameters

From: Shelley <randomshelley_at_gmail.com>
Date: Thu, 6 Dec 2007 10:30:05 -0600

What are some common practices for creating queries with a dynamic number of
parameters in the IN clause?
  SELECT e FROM ENTITY e WHERE e.id IN (?1, ?2, ..., ?n)

Is there any possible way to create a named query for this scenario? It
seems that this is might be a fairly common scenario that would be ideal if
JPA could handle. I've considered several options (ex: using dynamic
queries, creating multiple named queries with different numbers of
parameters, etc.), but none of them are optimal.