24

使用 Hibernate 的标准,我想执行相当于:

select distinct uspscity, state from citycomplete where USPSCITY = 'HOUSTON'

我认为执行以下操作会产生我想要的结果:

ProjectionList projList = new ProjectionList();
projList.add(Projections.distinct(Projections.property("id.state")));
projList.add(Projections.distinct(Projections.property("id.uspsCity")));
criteria.setProjection(projList);

但是,这实际上是执行如下操作:

select distinct uspscity, distinct state from citycomplete where USPSCITY = 'HOUSTON'

这显然会引发错误。

除了不使用 Criteria 之外,还有其他解决方案吗?

谢谢,

布兰登

4

1 回答 1

55
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("id.state"));
projList.add(Projections.property("id.uspsCity"));
criteria.setProjection(Projections.distinct(projList));
于 2011-03-04T16:09:12.113 回答