hibernate - How to build DetachedCriteria with aggregation of foregin field? -


tables structure:

tables

to aggregate total amount of goods sql easy:

select      sum(i.count) total_goods operation op     inner join order ord          on op.orderid = ord.id     inner join item itm          on itm.orderid = ord.id     op.datecreated < '2015-07-01 00:00:00' 

but how detachedcriteria?

int gettotalgoods(detachedcriteria filteredoperations) {    // contains date filter    filteredoperations.build {        projections {            // 'order' entity has one-to-many association 'items'            sum('order.items.count')        }    }.list().get(0) ?: 0 } 

this code fails with:

could not resolve property: order.items.count of: com.operation


Comments