我有以下查询,我按城市名称排序,并有条件地进行排序:
String sql;
if(sortingNeeded) {
sql = SELECT distinct m, ma FROM Merchant m INNER JOIN m.merchantAddresses ma where m.type = 0 order by ma.city;
} else {
sql = SELECT distinct m FROM Merchant m where m.type = 0;
}
Query query = getEntityManager().createQuery(sql.toString(), Merchant.class);
query.getResultList();
问题是在订购时,我也需要退回merchantAddress
,因此不需要。由于我要返回merchantAddress
,因此不会将其映射到商家实体。我可以做些什么来改善?