I have the following class structure
public class Emp implements java.io.Serializable {
....
}
public interface EmployeeDAO {
public List<Emp> findAllEmployees();
}
public class EmployeeDAOImpl implements EmployeeDAO {
public List<Emp> findAllEmployees() {
CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(Emp.class));
return getEntityManager().createQuery(cq).getResultList();
}
...
}
Issue I am having is
return getEntityManager().createQuery(cq).getResultList();
The above line gives me the following error, what could be the reason for this?
incompatible types; found: interface java.util.List<java.lang.Object>,
required: interface java.util.List<test.entity.Emp>
The same code works in other higher version of Java. My current JDK is 1.6
You didn't tell the CriteraQuery
which type it will return.
public List<Emp> findAllEmployees() {
CriteriaQuery<Emp> cq = getEntityManager().getCriteriaBuilder().createQuery(Emp.class);
cq.select(cq.from(Emp.class));
return getEntityManager().createQuery(cq).getResultList();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.