我有一个列表,我需要对其进行迭代,即使在使用 Iterator 或 for 循环之后,它也会给我类转换异常,给我的问题是
代码如下,
List<DataLoaderIndex> dataList = new ArrayList<DataLoaderIndex>();
dataList = dataLoaderIndexDAO.getDataSourceStatus(uploadFrequency,reportEndDate);
Map<String,String> mapData = new HashMap<String,String>();
Iterator<DataLoaderIndex> itrObj = dataList.iterator();
while (itrObj.hasNext()) {
DataLoaderIndex dlObj = itrObj.next();
String dsName = dlObj.getDataSourceType();
String dsStatus = dlObj.getStatus();
mapData.put(dsName, dsStatus);
}
/*for(int i=0;i<dataList.size();i++){
String dsName = dataList.get(i).getDataSourceType();
String dsStatus = dataList.get(i).getStatus();
mapData.put(dsName, dsStatus);
}*/
DAO 部分在这里:
public List<DataLoaderIndex> getDataSourceStatus(String uploadFrequency,String reportEndDate){
List<DataLoaderIndex> dataList = null;
if(session!=null){
Query query = session.createQuery("select dataSourceType,uploadedBy,status from DataLoaderIndex where DATE (reportEndDate) =:endate and UPPER(reportFreq) = UPPER(:uploadFreq)");
query.setString("endate", reportDate);
query.setString("uploadFreq", uploadFrequency);
dataList = query.list();
}
return dataList;
}
我得到了这条线的例外
String dsName = dlObj.getDataSourceType();
...
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.work.in.synct.entity.DataLoaderIndex
at com.work.synct.service.dataloaderimpl.DataUploadDetailsService.getUploadStatus(DataUploadDetailsService.java:36)