I think that the section 15.6. The select clause covers what you’re trying to achieve:
15.6. The select clause
…
Queries can return multiple objects
and/or properties as an array of type
Object[]
:select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
Or as a
List
:select new list(mother, offspr, mate.name) from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
Or – assuming that the class
Family
has an appropriate constructor – as an
actual typesafe Java object:select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr
In your case, you probably want:
SELECT new MyCustomList(product.code, SUM(product.price), COUNT(product.code))
from Product AS product
GROUP BY product.code
Where MyCustomList
is not necessarily a mapped entity.