I have a fairly complex data model and consequently a fairly complex query (using criteria API):
This is my criteria:
Criteria criteria = getSession().createCriteria(MyClass.class);
criteria.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(Restrictions.eq("issuer.id", issuerCompanyId));
criteria.addOrder(Order.desc("product.id"));
criteria.setFirstResult(pagingParams.getDisplayStart())
.setMaxResults(pagingParams.getDisplayLength());
List<MyClass> result = criteria.list()
Nothing more, nothing skipped.
If I now look at the generated SQL (pretty huge statement), it ends like this:
...and this_.issuer_id=? order by underlying12_.ric asc, this_.product_id desc
And here is my problem: The order by underlying12_.ric asc is completely unwanted, and of course it results in a wrong ordering of my result.
I have absolutely no clue where the statement comes from and how I can get rid of it. Any help is welcome 🙂
Update: Found the order by statement in my very own code. This question can certainly be closed.
My bad. Just discovered this mapping from product to underlying:
@OrderBy(value=”ric”)
private Set underlyings = new HashSet();