CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Foo> from = cq.from(Foo.class);
MapJoin<Foo, Bar, Long> joinMap = from.joinMap("map");
Path<Bar> key = joinMap.key();
Path<Long> id = key.get("id");
cq.select(id);
entityManager.createQuery(cq).getResultList();