Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Query nativeQuery = em.createNativeQuery("SELECT e.employee_id," +
- "e.first_name," + "e.last_name," + "e.department_id As id," +
- " e.salary " + " FROM employees AS e " + " JOIN departments AS d " +
- " ON d.department_id = e.department_id " +
- " WHERE d.name = 'Research and Development'" +
- " ORDER BY e.salary ASC, e.first_name DESC");
- List<Object[]> employeeList = nativeQuery.getResultList();
- for (Object[] object : employeeList) {
- int pk = (int) object[0];
- int departmentPk =(int) object[3];
- Employee employee = em.find(Employee.class, pk);
- Department department = em.find(Department.class, departmentPk);
- System.out.println(String.format("%s %s from %s - $%.2f",
- employee.getFirstName(), employee.getLastName(),
- department.getName(), employee.getSalary()));
- }
Advertisement
Add Comment
Please, Sign In to add comment