Rob*_*t H 1 java hibernate jpa hashmap
我正在使用Hibernate JPA运行本机查询并返回结果列表.
我想要的结果列表并添加到地图中以供将来处理,但返回的地图仅包含ResultList中的最后一项.
如何让结果列表在地图中添加多个条目?
Map<String,String> results = new HashMap<>();
Query query = em.createNativeQuery(select);
List<Object[]> resultSet = query.getResultList();
for(Object[] o : resultSet){
System.out.println(o[0] + "\t"+ o[1]); //this prints out the columns correctly
results.put((String)o[0],(String)o[1]); //but this only ever holds the last displayed column
}
Run Code Online (Sandbox Code Playgroud)
- 编辑 -
预期地图内容:
940 7107877
940 7107664
940 7112778
940 7112479
940 7114678
940 7113504
println输出
940 7107877
940 7107664
940 7112778
940 7112479
940 7114678
940 7113504
调试器输出
从下图中你可以看到结果大小= 1,显示对象的结果集的样本,以及i计数器(我添加它来说明我正在进行的迭代)

| 归档时间: |
|
| 查看次数: |
740 次 |
| 最近记录: |