Convert JQL to CriteriaBuilder

OK .. I'm stuck.

Can someone help me convert this JQL

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

is a collection of Enum. It's hard for me to convert the WHERE part. I do not understand why the CriteriaBuilder.IN method gets only one value.

Can anybody help me?

+2
source share
1 answer

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);
+4
source

Source: https://habr.com/ru/post/1777616/


All Articles