Here you go : I have used CriteriaBuilder to count them ... as a result, you get a List of Tuple containing the user login and count elements ... you may want to change names and "count cases" according to your needs :
public List<Tuple> test() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
Root<Designation> designation = cq.from(Designation.class);
Join<Designation, Commande> commande = designation.join("commande");
Join<Commande, User> user = commande.join("user");
Expression expr = commande.get("commandeTms");
cq.multiselect(user.get("login").alias("login"),
cb.sum(cb.<Long>selectCase().when(expr.isNotNull(), 1L).otherwise(0L)).alias("NotNull"),
cb.sum(cb.<Long>selectCase().when(expr.isNull(), 1L).otherwise(0L)).alias("Null"));
cq.groupBy(user.get("login"));
Query query = entityManager.createQuery(cq);
return query.getResultList();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…