java.util.ArrayList cannot be cast to com.hxll.hr.entity.SalaryStandard
本帖最后由 aoyiufuwa 于 2012-11-25 21:30:49 编辑
报错:
Hibernate: select salarystan0_.SSD_ID as SSD1_25_, salarystan0_.STANDARD_ID as STANDARD2_25_, salarystan0_.STANDARD_NAME as STANDARD3_25_, salarystan0_.DESIGNER as DESIGNER25_, salarystan0_.REGISTER as REGISTER25_, salarystan0_.CHECKER as CHECKER25_, salarystan0_.CHANGER as CHANGER25_, salarystan0_.REGIST_TIME as REGIST8_25_, salarystan0_.CHECK_TIME as CHECK9_25_, salarystan0_.CHANGE_TIME as CHANGE10_25_, salarystan0_.SALARY_SUM as SALARY11_25_, salarystan0_.CHECK_STATUS as CHECK12_25_, salarystan0_.CHANGE_STATUS as CHANGE13_25_, salarystan0_.CHECK_COMMENT as CHECK14_25_, salarystan0_.REMARK as REMARK25_ from SALARY_STANDARD salarystan0_ where salarystan0_.STANDARD_ID like '10004'
Exception in thread "main"
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.hxll.hr.entity.SalaryStandard
at com.hxll.hr.dao.impl.SalaryStandardDaoImpl.salaryStandardId(SalaryStandardDaoImpl.java:88)
at com.hxll.hr.dao.impl.SalaryStandardDaoImpl.main(SalaryStandardDaoImpl.java:95)
声明一下这个com.hxll.hr.entity.SalaryStandard是实体类。
我运行这段代码:
/**
* 薪酬标准信息编号查询
*/
public SalaryStandard salaryStandardId(String standardId) {
String hql = "from SalaryStandard s where s.standardId like '"+standardId+"'";
return (SalaryStandard)super.
getHibernateTemplate().find(hql);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
SalaryStandardDaoImpl salaryStandardDao=(SalaryStandardDaoImpl)context.getBean("salaryStandardDao");
salaryStandardDao.salaryStandardId("10004");
System.out.println(salaryStandardDao);
}
------最佳解决方案--------------------find方法返回的是一个List,你的salaryStandardId方法的返回值应该改成List<SalaryStandard>
------其他解决方案--------------------基础问题呀。。。
你接收 用 SalaryStandard
返回类型实际是一个List
------其他解决方案--------------------实体类:
/**
* 薪酬标准基本信息表
*
*/
public class SalaryStandard implements java.io.Serializable {
private Long ssdId;
private String standardId;// 薪酬标准单编号
private String standardName;// 薪酬标准单名称
private String designer;// 制定者名字
private String register;// 登记人
private String checker;// 复核人
private String changer;// 变更人
private Date registTime;// 登记时间
private Date checkTime;// 复核时间
private Date changeTime;// 变更时间
private Long salarySum;// 薪酬总额
private Long checkStatus;// 是否经过复核
private Long changeStatus;// 更改状态
private String checkComment;// 复核意见
private String remark;// 备注