IN EJB-QL I am trying to create a query like this:
WHERE id IN ([id1],[id2],[id3],...);
This is a normal query for oracle or mysql but how can I make EJB-QL set parameters as a list?
WHERE ClassNameId IN (List<Long> listOfIds);
is there a way to do this?
More importantly is would this be more efficient then running a separate query for each id in the list?
Any suggestions would be appreciated.
Edit: For clarity I am trying to run one query to return multiple rows based on a list of ids (not the entire table, not the contents of another table, but an arbitrary list of ids). I am hoping to be able to run this query once instead of running a normal find query multiple times (once for each of the ids in the list).
String queryStr = "select o from ClassName o where o.classNameId IN :ids"; Query query = entityManager.createQuery("queryStr"); List<Long> listOfIds = getIds(); query.setParameter("ids", listOfIds); List<ClassName> classNameList = (List<ClassName>) query.getResultList();
I'm not an expert with EJB-QL. You might find the examples from here useful.
SELECT OBJECT (o) FROM Order AS o IN (o.lineItems) li WHERE li.quantity = ?1