开发者

Convert JQL to CriteriaBuilder

OK.. I'm stuck.

Can someone help me converting this JQL

SELECT a FROM Asset a WHERE ?1 IN (SELECT c FROM a.categories c)

categories is a collection of Enum. I have difficulty converting the 开发者_如何转开发WHERE part. I don't understand why method CriteriaBuilder.IN only receive one value.

Anyone can help me?


Try something like:

        CriteriaBuilder qb = em.getCriteriaBuilder();
        CriteriaQuery<Asset> cq = qb.createQuery(Asset.class);
        Root<Asset> asset = cq.from(Asset.class);
        cq.where(qb.parameter(Category.class, "category").in(asset.<Collection<?>>get("categories"))));
        Query query = em.createQuery(cq);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜