这是我在Hibernate中尝试的SQL查询。
Hibernate: select this_.pName as y0_, this_.kNum as y1_, count(*) as y2_ from ALL_CPView this_ inner join ALL_AMView aID1_ on this_.agentid=aID1_.AgentID
Criteria crit = statelessSession.createCriteria(APRecord.class, "apr")
.createAlias("manageID", "ID", Criteria.INNER_JOIN);
crit.setProjection(Projections.projectionList()
.add(Projections.groupProperty("PName"), "PName")
.add(Projections.groupProperty("kNum"), "kNum")
.add(Projections.rowCount() , "count"));
results = crit.setResultTransformer(Transformers.aliasToBean(APStat.class)).list();
现在我正在尝试编写一个DetachedCriteria子查询,但它不起作用。到目前为止我所拥有的:
DetachedCriteria pCrit = DetachedCriteria.forClass(APRecord.class);
crit.add(Subqueries.propertyIn("agentid", pCrit.setProjection(Projections.property("agentid"))));
projList = Projections.projectionList();
projList.add(Projections.countDistinct("agentid"));
crit.setProjection(projList);
有人能说出我错过了什么吗?任何帮助表示赞赏。