Hi Dominicus,
I got in working thanks to you. Here is the working solution I have now:
Code:
Criteria stackedProductsCriteria = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(StackedProduct.class)
.createAlias("orderProduct", "orderProduct")
.createAlias("orderProduct.product", "product")
.createAlias("product.crate", "crate");
Criteria deliveryOrderCriteria = stackedProductsCriteria.createCriteria("orderProduct.deliveryOrder");
deliveryOrderCriteria = createDeliveryOrderCriteria(deliveryOrderCriteria);
stackedProductsCriteria.setProjection(Projections.projectionList()
.add(Projections.groupProperty("crate.type"), "type")
.add(Projections.sum("noOfCrates"), "noOfCrates"));
List <CrateStatsBean> list = stackedProductsCriteria.setResultTransformer(Transformers.aliasToBean(CrateStatsBean.class)).list();
I explicitly set all the associations with createAlias() as you can see and then just used "
crate.type" in the Projections.groupProperty() as you suggested.
Thanks a lot for your help, I really appreciate it.
Rory