0
我在Java程序中有一个非常奇怪的行为。我有很长很长的HashMap,从方法检索,但是当我试图从它那里得到的信息,此HashMap是一个字符串,字符串没有任何错误,也没有警告..下面我的代码:奇怪的错误Java Hashmap类型长,字符串
List<HashMap<Long, Long>> getAggregateResult(String idCheptel, Integer limit) {
StringBuilder hql = new StringBuilder();
hql.append("select new map(t.prod.id, count(t.prod.id))");
... //rest of implem.
return entityManager.createQuery(hql.toString()).setMaxResults(limit).getResultList();
}
呼叫功能
... //in other method try to retrieve the information
for (HashMap<Long, Long> map : getAggregateResultVetProduct(idCheptel, limit)) {
System.out.println(">>>>>>>" + map.get(0L)); //always null
//the map is asked in Long, but in debugger it's a String, String
for (Map.Entry<Long, Long> entry : map.entrySet()) {
System.out.println("Key: " + entry.getKey()); //here key are 0
System.out.println("Value: " + entry.getValue());
}
}
的如果有人可以给我一些信息,为什么会出现这种行为。谢谢。
编辑
这里的一些信息: 我使用的IntelliJ。在调试器的屏幕截图下方,因为它被问到。
你能显示你引用的调试器输出或屏幕截图吗? –
getAggregateResultVetProduct的做法是什么? – mvera
我猜也是entityManager.createQuery不返回一个HashMap。 – mvera