【发布时间】:2013-06-02 02:31:13
【问题描述】:
product_template、product_account、product_style 和 product_account 是表。 mysql命令:
select distinct product_template.id as ptid from product_account inner join product on product_account.productId=product.id inner join product_style on product.productStyleId=product_style.id inner join product_template on product_style.productTemplateId=product_template.id where product_account.sellerId=1 and product_account.productAccountType=1;
Mysql 命令工作正常,但我不知道如何在标准中实现。
我的代码:
Criteria c = createCriteria(ProductAccount.class);
ProjectionList projectionList = Projections.projectionList();
c.add(Restrictions.eq("seller", query.getSeller()));
c.add(Restrictions.eq("productAccountType", query.getProductAccountType()));
c.createCriteria("product").createCriteria("productStyle").createCriteria("productTemplate");
c.setProjection(Projections.distinct(Projections.property("id")));
List<Object> objects = c.list();
我只获得 product_account 的 id,但我需要 product_template 的 id。任何将不胜感激。提前致谢。
【问题讨论】:
-
你能贴出pojo类的实现吗
-
您的
createCriteria方法实现可能不正确。请将其包含在问题中。