I’m trying to do something which is easy as pie in PHP & Co:
SELECT COUNT(x) as numItems, AVG(y) as average, … FROM Z
In PHP I would get a simple array like [{ numItems: 0, average: 0 }] which I could use like this:
echo "Number of Items: " . $result[0]['numItems'];
Usually in JPQL you only query single objects or single columns and get Lists types, for example List<SomeEntity> or List<Long>. But what do you get, when querying multiple columns?
You get an
Object[](or aList<Object[]>). From the section 4.8.1 Result Type of the SELECT Clause of the JPA 1.0 specification:If you want strong typing, you can use a constructor expression in the SELECT clause. From the section 4.8.2 Constructor Expressions in the SELECT Clause: