我正在寻找相当于这个JPQL查询的JPA 2标准:
select e from Entity e join e.myMap m where KEY(m) = 'myKey' and VALUE(m) = ‘myValue’
谢谢!
答案 0 :(得分:6)
未经测试,但我想这应该没问题:
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")));