Reputation: 97
I'm looking for JPA 2 criteria equivalent of this JPQL query :
select e from Entity e join e.myMap m where KEY(m) = 'myKey' and VALUE(m) = ‘myValue’
Thank you !
Upvotes: 4
Views: 6356
Reputation: 691635
Not tested, but I guess this should be OK:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Entity> criteria = cb.createQuery(Entity.class);
Root<Entity> entity = criteria.from(Entity.class);
MapJoin<Entity, String, String> mapJoin = entity.joinMap(Entity_.myMap);
criteria.where(cb.and(cb.equal(mapJoin.key(), "myKey"),
cb.equal(mapJoin.value(), "myValue")));
Upvotes: 6