To acces the property of productDTO you must join it. There're two ways of expression join in the Criteria API:
1. Use method createCriteria() of the Criteria interface:
Criteria cq = session.createCriteria(ShopDTO.class); Criteria productCriteria = cq.createCriteria("productDTO"); productCriteria.add(Restrictions.eq("productDTO.ID", productCode.toString())); //ID is the PK of product// productCriteria.add(Restrictions.eq("productDTO.productAbbreviated", productAbbr.toString()));
cq.list();
2. Assign an alias to the joined entity:
session.createCriteria(ShopDTO.class) .createAlias("productDTO", "productDTO") .add(Restrictions.eq("productDTO.ID", productCode.toString())) .add(Restrictions.eq("productDTO.productAbbreviated", productAbbr.toString())) .list();
_________________ Best Regards
|