开发者

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?

开发者_如何学C

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜