I think it would be good to mention that in this case "c" has to be typed as well.The right way would be: TypedQuery<Employee> q = em.createQuery(c);
Question :
Would it work if CriteriaQuery, Root and TypedQuery are not typed?The cast for the return value is not really required (but is not wrong). The following will work as well: List<Employee> returnValue = q.getResultList();