Your query is right and only thing you need to get distinct customer since same product customer may have ordered more than once
query = "SELECT distinct(o.customer)"
"FROM Order o "+
"WHERE o.productId = :productId"
Get Customer :
Query qry = em.createNamedQuery("GetCustomersByProduct");
List<Customer> resultList = qry.getResultList();