The following is a HQL from chapter 14.14 of the reference documentation
Code:
select order.id, sum(price.amount), count(item)
from Order as order
join order.lineItems as item
join item.product as product,
Catalog as catalog
join catalog.prices as price
where order.paid = false
and order.customer = :customer
and price.product = product
and catalog = :currentCatalog
group by order
having sum(price.amount) > :minAmount
order by sum(price.amount) desc
If I want to have more order attributes along with the sum and count, how to modify this HQL? I think it should be something like
Code:
select new Order(order.id, ..., sum(price.amount), count(item))
from Order as order ...
where the sum and count can be defined as @Transient attributes in the Order object. But, it won't work.
How to solve this problem?