tags:

views:

45

answers:

1

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?

+1  A: 

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);
James
seems that the bug is with Hibernate. With OpenJPA this works as also using: asset.get("categories").in(category)
nanda