szvx4x wrote:
Session session = (Session) entityManager.getDelegate();
Criteria crit = session.createCriteria(MerchantReport.class);
crit.setFetchMode("merchant", FetchMode.SELECT);
crit.setFetchMode("reportConfig", FetchMode.SELECT);
crit.setMaxResults(20);
crit.setFirstResult(1);
Criteria merchantCrit = crit.createCriteria("merchant");
Criteria reportConfigCrit = crit.createCriteria("reportConfig");
if (SearchUtils.hasSearchValue(name)) {
merchantCrit.add(Restrictions.like("name", "%" + name + "%"));
}
merchantCrit.addOrder(Order.desc("name"));
reportConfigCrit.addOrder(Order.asc("displayName"));
List<MerchantReport> dbMerchantReports = crit.list();
The error I am getting is:
Caused by: org.hibernate.QueryException: could not resolve property: reportConfig.displayName of: com.cfna.mss.model.entity.MerchantReport
I am stumped. I can order by MerchantReport merchant.name but can't on the ReportInstance reportConfig.displayName. FetchMode on both the merchant and reportInstance are set to EAGER.
I'm pretty certain that projections and orders really only apply to the base Criteria.
I would try:
1. crit.addOrder(Order.asc("reportConfig.displayName"));
or
1. crit.createAlias("reportConfig", "reportConfig");
2. crit.addOrder(Order.asc("reportConfig.displayName"));
On another note, the Restrictions class provides a MatchMode class for LIKE queries. I would look into that.