try {
Session s = NewHibernateUtil.getSessionFactory().openSession();
Criteria c = s.createCriteria(Product.class);
c.add(Restrictions.eq("Gender", "Men"));
c.setResultTransformer(c.DISTINCT_ROOT_ENTITY);
List<Product> pList = c.list();
String size = "<option>Select size</option>";
for (Product p : pList) {
size += "<option>"+p.getProductSize()+"</option>";
}
resp.getWriter().write(size);
} catch (Exception e) {
e.printStackTrace();
}
I need to remove all duplicated sizes form the product but this wont work for me any suggustions
Change line
c.setResultTransformer(c.DISTINCT_ROOT_ENTITY);
with
c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
Try this:
c.setProjection( Projections.projectionList().add(
Projections.distinct(Projections.property("productSize")
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.