我尝试使用Criteria获得单列结果,但我没有得到该
的完美输出Criteria criteria = session.createCriteria(GroupName.class)
.setProjection(Projections.property("groupName"));
criteria.createAlias("gcmUsers", "user").setResultTransformer(
Criteria.DISTINCT_ROOT_ENTITY);
criteria.add(Restrictions.eq("user.clientName", userName));
groupNames=criteria.list();
i am getting this output :
Default, Default, Default, Default, Default, Default, twiter_grp
but my actual output is :
Default, twiter_grp,friends
答案 0 :(得分:1)
您可以使用Projections.distinct方法
Criteria criteria = session.createCriteria(GroupName.class)
.setProjection(Projections.distinct(Projections.property("groupName")));
criteria.createAlias("gcmUsers", "user").setResultTransformer(
Criteria.DISTINCT_ROOT_ENTITY);
criteria.add(Restrictions.eq("user.clientName", userName));
groupNames=criteria.list();