我正在尝试从 hsql db 中读取某些值,这些值作为带有键和值的映射返回。我还有另一种方法可以接受这些地图值并对其进行迭代并根据条件获取某些值。在此之后它将所有这些值添加到列表中。对我来说,条件和第一种方法工作正常,但是在将值添加到列表时,我面临类转换异常
从表中读取值的方法:
List<EntityMap> sample = session.createQuery(" FROM EntityMap order by if.ifName").list();
for (Iterator<EntityMap> iterator = sample.iterator(); iterator.hasNext();) {
entityMap = (EntityMap) iterator.next();
if (IfName != entityMap.getIf().getIfName().toString()) {
IfName = entityMap.getIf().getIfName().toString();
entitymapobject = new ArrayList<EntityMap>();
}
entitymapobject.add(entityMap);
EntityMaplist.put(entityMap.getIf().getIfName(),entitymapobject);
}
tx.commit();
此方法返回一个地图,它具有从数据库中获取的值。之后,我尝试根据某些条件提取某些值。在此我正在调用上述方法并遍历它
proertyMap = listPROPERTNAMES();
System.out.println("inside loadproperty");
for (Iterator<Integer> itr1 = srcEntityIDList.iterator(); itr1.hasNext();) {
Integer aInteger = itr1.next();
for (Map.Entry<Long, List<PropertyMap>> entry : proertyMap.entrySet()) {
System.out.println(aInteger);
System.out.println(entry.getKey());
Long aLong = entry.getKey();
if (aLong.equals(Long.valueOf(aInteger))) {
System.out.println("values are equal");
trgtPropNameList.add(( (PropertyMap) entry.getValue()).getTgtpropnm());
}
}
}
return trgtPropNameList;
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
return EntityMaplist;
}
在尝试将值添加到列表 (trgtPropNameList) 时,我得到了一个类转换异常。我的具有 setter 和 getter 方法的 POJO 类是
public class PropertyMap implements java.io.Serializable {
private PropertyMapId id;
private EntityMap entityMap;
private String tgtpropnm;
private String splitrule;
private String combinerule;
private String createdby;
private Date createdon;
public PropertyMap() {
}
public PropertyMap(PropertyMapId id, EntityMap entityMap) {
this.id = id;
this.entityMap = entityMap;
}
public PropertyMap(PropertyMapId id, EntityMap entityMap, String tgtpropnm,
String splitrule, String combinerule, String createdby,
Date createdon) {
this.id = id;
this.entityMap = entityMap;
this.tgtpropnm = tgtpropnm;
this.splitrule = splitrule;
this.combinerule = combinerule;
this.createdby = createdby;
this.createdon = createdon;
}
public PropertyMapId getId() {
return this.id;
}
public void setId(PropertyMapId id) {
this.id = id;
}
public EntityMap getEntityMap() {
return this.entityMap;
}
public void setEntityMap(EntityMap entityMap) {
this.entityMap = entityMap;
}
public String getTgtpropnm() {
return this.tgtpropnm;
}
public void setTgtpropnm(String tgtpropnm) {
this.tgtpropnm = tgtpropnm;
}
public String getSplitrule() {
return this.splitrule;
}
public void setSplitrule(String splitrule) {
this.splitrule = splitrule;
}
public String getCombinerule() {
return this.combinerule;
}
public void setCombinerule(String combinerule) {
this.combinerule = combinerule;
}
public String getCreatedby() {
return this.createdby;
}
public void setCreatedby(String createdby) {
this.createdby = createdby;
}
public Date getCreatedon() {
return this.createdon;
}
public void setCreatedon(Date createdon) {
this.createdon = createdon;
}
}
任何人都可以在这里帮助我吗?