Query q1 = em.createQuery("SELECT e.name, e.salary FROM Employee e");
List<Object[]> result1 = q1.getResultList();
for (Object[] resultElement : result1) {
String name = (String)resultElement[0];
Double salary = (Double)resultElement[1];
...
}
Query q2 = em.createQuery("SELECT e.name, e.salary, e.department FROM Employee e");
List<Object[]> result2 = q2.getResultList();
for (Object[] resultElement : result2) {
String name = (String)resultElement[0];
Double salary = (Double)resultElement[1];
Department dept = (Department)resultElement[2];
...
}
Query q3 = em.createQuery("SELECT COUNT(e), SUM(e.salary) FROM Employee e");
Object[] result3 = (Object[])q3.getSingleResult();
Long count = (Long)result3[0];
Double sum = (Double)result3[1];