Answer the question
In order to leave comments, you need to log in
What's wrong with Criteria Query?
What is wrong with my request? You need to select certificates that have an association with the list of tags (AND condition).
There is a request:
Set<String> tagNames = ...
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<GiftCertificate> criteriaQuery = builder.createQuery(GiftCertificate.class);
Root<GiftCertificate> root = criteriaQuery.from(GiftCertificate.class);
Root<GiftCertificateToTagRelation> relationRoot = criteriaQuery.from(GiftCertificateToTagRelation.class);
Join<GiftCertificateToTagRelation, Tag> tagJoin = relationRoot.join(ParameterName.TAG);
Predicate condition = tagJoin.get(ParameterName.NAME).in(tagNames);
criteriaQuery.where(condition).groupBy(root);
select *
from gift_certificate gc
cross join gift_certificate_to_tag_relation r
inner join tag t on r.tag_id = t.id
where t.name in (?, ?)
group by r.gift_certificate_id;
select *
from gift_certificate gc
cross join gift_certificate_to_tag_relation r on r.gift_certificate_id = gc.id
inner join tag t on r.tag_id = t.id
where t.name in (?, ?)
group by r.gift_certificate_id;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question