I have a pretty complex criteria, which I use to retrieve, sort and page server-side data. I stripped down the following excerpt:
// create criteria over a bunch of tables...
Criteria testCriteria = getSession().createCriteria(PriceRequest.class)
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setFetchMode("pricedBy", FetchMode.JOIN)
.setFetchMode("canceledBy", FetchMode.JOIN)
.setFetchMode("product", FetchMode.JOIN)
.setFetchMode("product.underlyings", FetchMode.JOIN)
.setFetchMode("product.tradedBy", FetchMode.JOIN)
.setFetchMode("product.requestedBy", FetchMode.JOIN)
.setFetchMode("fileUploads", FetchMode.JOIN);
// add various filter fields (only if required in real code)...
Criteria subCriteria = testCriteria
.createCriteria("product", JoinFragment.LEFT_OUTER_JOIN)
.setFetchMode("underlyings", FetchMode.JOIN)
.add(Restrictions.ge("maturityDate", new Date()));
testCriteria.addOrder(Order.desc("product.id")); // (1)
testCriteria.addOrder(Order.desc("product.maturityDate")); // (2)
List list = testCriteria.list();
Statement (1) runs fine, statement (2) ends with the following exception:
SEVERE: Servlet.service() for servlet rest threw exception org.hibernate.QueryException: could not resolve property: product.maturityDate of: com.my.model.PriceRequest
I picked "maturityDate" as an example, but I'm having this issues with all product properties except "product.id".
I also tried adding an alias for product ("prod"). This allows to sort by maturity date ("prod.maturityDate"), but fails on adding the restriction to subcriteria.
I so much have no clue what's going wrong...