当前位置: 动力学知识库 > 问答 > 编程问答 >

java - EJB-QL question how would I set a list as a parameter like: select o from table where id in (List<Long> listOfIds)

问题描述:

IN EJB-QL I am trying to create a query like this:

SELECT *

FROM table

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?

SELECT o

FROM ClassName

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).

Thanks,

Jim

网友答案:
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
分享给朋友:
您可能感兴趣的文章:
随机阅读: