2017年2月20日上午10時04分26秒org.apache.catalina.core.StandardWrapperValve 調用重度:Servlet.service()進行的servlet [調度員]上下文 帶路徑[/ sinisukasystem]引發異常[請求處理 失敗;嵌套異常是java.lang.ClassCastException: java.lang.Integer不能轉換爲com.hendri.domain.ProductType] ,並存在根本原因java.lang.ClassCastException:java.lang.Integer不能將 轉換爲com.hendri在 com.hendri.dao.EmployeeDAOImpl.getAllEmployees(EmployeeDAOImpl.java:83) .domain.ProductType在 com.hendri.service.EmployeeServiceImpl.getAllEmployees(EmployeeServiceImpl.java:49) 在sun.reflect.NativeMethodAccessorImpl.invoke0 (本機方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.ClassCastException在Spring-Hibernate項目
@SuppressWarnings("unchecked")
@Override
public List<Employee> getAllEmployees(String employeeName) {
String query = "SELECT e.* FROM Employees e WHERE e.name like '%"+ employeeName +"%'";
List<Object[]> employeeObjects = hibernateUtil.fetchAll(query);
List<Employee> employees = new ArrayList<Employee>();
//List<ProductType> producttype = new ArrayList<ProductType>();
for(Object[] employeeObject: employeeObjects) {
Employee employee = new Employee();
long id = ((BigInteger) employeeObject[0]).longValue();
int age = (int) employeeObject[1];
String name = (String) employeeObject[2];
float salary = (float) employeeObject[3];
ProductType productType = (ProductType) employeeObject[4];
employee.setId(id);
employee.setName(name);
employee.setAge(age);
employee.setSalary(salary);
employee.setProductType(productType);
employees.add(employee);
}
System.out.println(employees);enter code here
return employees;
}
請分享Employee類,並與數據庫列的休眠映射。 –
'ProductType productType =(ProductType)employeeObject [4];'您可能在此列中存儲了一個數字。 – vegemite4me
你的問題是什麼? –