$query = $entityManager->createQuery(
'SELECT MAX(employee.salary) FROM
AppBundle:Employee employee
JOIN AppBundle:Department department
WHERE department.id = :id'
)->setParameter('id', $department->getId());
$result = $query->getSingleScalarResult();
SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
JOIN employee.department department
WHERE department.id = :id
SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
WHERE IDENTITY(employee.department) = :id