开发者

Using Hibernate's Criteria and Projections to Select Multiple Distinct Columns

开发者 https://www.devze.com 2023-02-14 16:59 出处:网络
Using Hibernate\'s Criteria, I want to execute the equivalent of: select distinct uspscity, state from citycomplete where USPSCITY = \'HOUSTON\'

Using Hibernate's Criteria, I want to execute the equivalent of:

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

I thought doing the following would yield the results I wanted:

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

But, what this actually does is execute som开发者_Python百科ething like:

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

Which throws an error, obviously.

Other than not using Criteria, is there a solution for this?

Thanks,

Brandon


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号