2013-03-05 59 views
0

我想讀取hsql數據庫中的某些值,並將這些值作爲具有鍵和值的映射返回。我還有一個方法可以接受這些映射值,並將遍歷它並根據條件獲取某些值。之後,它會將所有這些值添加到列表中。對我來說,條件和第一種方法是工作正常,但同時增加值到列表我對着類轉換異常Hibernate java.util.ArrayList不能被轉換..類轉換異常

方法,從表中讀取值:

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(); 

這個方法返回一個地圖,它具有從數據庫中獲取的值。在那之後我試圖基於某種conditions.In此,我呼籲上述方法提取一定的值,我通過它遍歷

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)我得到一個類拋出異常。它具有調節器和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; 
    } 
} 

任何人都可以請幫我在這裏?

回答

2

entry.getValue()List<PropertyMap>類型的對象和不PropertyMap

0

如果你不能施放它只是構建並填寫一個新的。

0

改變線

trgtPropNameList.add(((PropertyMap) entry.getValue()).getTgtpropnm()); 

for(PropertyMap map : entry.getValue(){ 
    trgtPropNameList.add(((PropertyMap)map).getTgtpropnm()); 
} 

應該解決鑄造問題。

相關問題