在编译代码时我得到了上述异常。代码是:
IPAMEmailManagerBean.java -
DAOFactory daoFactory = DAOFactory.getInstance();
PropertyDAO propertyDAO = (PropertyDAO) daoFactory.getDAO("org.hc.cbl.dao.property.PropertyDAO");
StringBuilder aaCategoryCode = new StringBuilder();
PropertyAACategoryCodesTO propertyAACategoryCodesTO = null;
List<String> ahrCategoryCodeList = new ArrayList<String>(Arrays.asList(applicantSavedSearchTO.getAccHousingCatIdStr().split(",")));
List<Long> list = new ArrayList<Long>();
for (String s : ahrCategoryCodeList)
list.add(Long.valueOf(s));
System.out.println(list);
List list1 = propertyDAO.findAHRCategoryCodesByPartnerIdAndCodeList1(applicantSavedSearchTO.getPartnerId(), list); //This line showing class cast exception java.util.ArrayList cannot be cast to java.lang.Long
if(list1!=null ){
for(int i=0;i<list1.size();i++){
propertyAACategoryCodesTO=(PropertyAACategoryCodesTO)list1.get(i);
aaCategoryCode.append(propertyAACategoryCodesTO.getAaCategoryCodeDesc()+",");
}
}
}
PropertyDAO.java -
public List findAHRCategoryCodesByPartnerIdAndCodeList1(Long partnerId, List strAHRCategoryCode)throws CBLException {
List AHRCategoryCodesList = null;
try {
log.debug("Entering PropertyAACategoryCodeDAO public List findAHRCategoryCodesByPartnerIdAndCodeList()throws CBLException");
Query query = HibernateUtil.getSession().createQuery("from PropertyAACategoryCodesTO as propertyAACategoryCodesTO "
+ "where propertyAACategoryCodesTO.partnerTO.partnerId=:partnerId and propertyAACategoryCodesTO.aaCategoryId "
+ "in(:strPropertyTypes) order by propertyAACategoryCodesTO.aaCategoryCodeDesc asc");
query.setLong("partnerId",partnerId);
query.setParameter("strPropertyTypes", strAHRCategoryCode);
query.setCacheable(true);
AHRCategoryCodesList=query.list();
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
} catch (Exception ce) {
ce.printStackTrace();
}
log.debug("Exit PropertyAACategoryCodeDAO public List findAHRCategoryCodesByPartnerIdAndCodeList()throws CBLException");
return AHRCategoryCodesList;
}
我已经将列表值强制转换,所以原因可能是什么原因。提前谢谢。
答案 0 :(得分:0)
它显示异常的原因是PropertyDAO.findAHRCategoryCodesByPartnerIdAndCodeList1()或它正在调用的方法之一试图将List强制转换为Long。