performing this query:
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
Root<Unit> root = query.from(Unit.class);
Expression<Class<? extends Unit>> type = root.type();
Expression<Long> count = builder.countDistinct(root);
query.multiselect(type, count);
query.groupBy(type);
List<Object[]> list = em.createQuery(query).getResultList();
a ClassCastException is thrown:
Instead, using plain JPQL, the query executes without problem:
String query = "select type(x), count(x) from Unit x group by type(x)";
return em.createQuery(query).getResultList();
Let me know if you need a test-case, I'll create it on github. Thank you |