开发者

Convert JQL to CriteriaBuilder

开发者 https://www.devze.com 2023-01-15 16:47 出处:网络
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)

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

精彩评论

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