我有一个带有投影和变换器的DetachedCriteria查询,如下所示
criteria = DetachedCriteria.forClass(Report.class, "r");
criteria
.createAlias("template", "t")
.createAlias("constituents", "c")
.setProjection(
Projections.projectionList()
.add(Projections.property("r.reportId").as("reportId"))
.add(Projections.property("r.reportNm").as("reportNm"))
.add(Projections.property("t.templateNm").as("templateNm"))
.add(Projections.property("t.templateTyp").as("templateTyp"))
).setResultTransformer(Transformers.aliasToBean(ReportSummary.class));
然后我从会话中获取Citeria,现在当我尝试动态添加orderBy子句时,即
Session session = entityManager.unwrap(Session.class);
Criteria c = criteria.getExecutableCriteria(session);
Order order = sortDirection.equals("ASC")?
Order.asc(orderByColumnName):Order.desc(orderByColumnName);
c.addOrder(order);
生成的查询包含一个额外的orderBy子句,即
order by reportId ASC(NOT REQUIRED ADDED AUTOMATICALLY), order by reportNm ASC
有人可以指导我一个解决方案