DISTINCT无法正常工作,如何解决此问题

时间:2018-08-18 11:08:47

标签: java hibernate

 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();
    }

我需要从产品中删除所有重复的尺寸,但这对我的建议都不起作用

2 个答案:

答案 0 :(得分:0)

更改行

c.setResultTransformer(c.DISTINCT_ROOT_ENTITY);

c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

答案 1 :(得分:0)

尝试一下:

var config = new LoggingConfiguration();
NLog.LogManager.Configuration = config;
NServiceBus.Logging.LogManager.Use<NLogFactory>();