final List <Map<String , Object>> roleList;
final Map<Integer, String> roleMap=new HashMap<Integer, String>();
roleList = getSession()
.createQuery("select Id, Name from Emp where dept=:ref")
.setParameter("ref", "accounts")
.list();
for (Map<String, Object> map2 : roleList)
{
roleMap.put((Integer)(map2.get("Id")), (String)map2.get("Name"));
}
MappingBean.setRoleList(roleMap);
Run Code Online (Sandbox Code Playgroud)
上面的代码显示了类转换异常[Ljava.lang.Object; cannot be cast to java.util.Map.在Hibernate中有什么办法我们可以以List of Maps的形式获取数据吗?我roleList是地图的形式,我想设置roleList.
我有hashmap Key是由3个元素(element1 + element2 + element3)串联而成的String
String key=element1+element2+element3;
Run Code Online (Sandbox Code Playgroud)
放在哈希图中
HashMap<String,Object> map=new Hashmap<String,Object>();
map.put(key,new Object());
Run Code Online (Sandbox Code Playgroud)
我想删除具有element2 if(key.contains(“ element2”))的hashmap匹配键中的所有条目,然后删除hashmap中的该条目。
如何做到这一点?