这是我尝试过的,
Criteria crv = ses.createCriteria(DB.Values.class);
crv.add(Restrictions.eq("categories", c));
crv.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<DB.Values> liv = crv.list();
它仍然提供重复值
这也不起作用,
Criteria crv = ses.createCriteria(DB.Values.class);
crv.add(Restrictions.eq("categories", c));
crv.setProjection(Projections.property("description"));
List<DB.Values> liv = crv.list();
答案 0 :(得分:0)
Criteria cr = ses.createCriteria(DB.Categories.class);
cr.add(Restrictions.eq("description", cat));
DB.Categories c = (DB.Categories) cr.uniqueResult();
Criteria crv = (Criteria) ses.createCriteria(DB.Values.class)
.setProjection(Projections.projectionList()
.add(Projections.distinct(Projections.property("description")))
);
crv.add(Restrictions.eq("categories", c));
List<String> liv = crv.list();
此代码回答了我的问题