Map Request Using JPA 2.0 Criteria

I am looking for the JPA 2 equivalent of this JPQL query:

select e from Entity e join e.myMap m where KEY(m) = 'myKey' and VALUE(m) = 'myValue' 

Thanks!

+4
source share
1 answer

Not tested, but I think it 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"))); 
+6
source

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


All Articles