是否可以将此查询编写为 TypedQuery 并让两个 Long 运行到一个内部有两个公共 Long 字段的对象中。
Query q = em.createQuery(
"SELECT c.id, COUNT(t.id) " +
"FROM PubText t " +
"JOIN t.comm c " +
"WHERE c.element = ?1 " +
"GROUP BY c.id");
q.setParameter(1, e);
List<?> rl = q.getResultList();
Iterator<?> it = rl.iterator();
HashMap<Long, Long> res = new HashMap<Long, Long>();
while (it.hasNext()) {
Object[] n = (Object[]) it.next();
res.put((Long)n[0], (Long)n[1]);
}
return res;