Close

JPA - How to get department name with maximum salary in JPQL?

JPA JAVA EE 

    private static void findHighestSalaryDept() {
System.out.println("-- Dept with max salary --");
EntityManager em = entityManagerFactory.createEntityManager();
TypedQuery<String> query = em.createQuery("SELECT d.name FROM Department d "
+ " JOIN d.employees e where e.salary = (SELECT MAX(e2.salary) FROM Employee e2) ",
String.class);
String dept = query.getSingleResult();
System.out.println(dept);
}
Original Post




See Also