java-如何在休眠中实现多个内部联接

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.任何将不胜感激.提前致谢.

解决方法:

这个

Criteria c = createCriteria();
c.add(Restrictions.eq("seller", query.getSeller()));
c.add(Restrictions.eq("productAccountType", query.getProductAccountType()));
c.createCriteria("product").createCriteria("productStyle").createCriteria("productTemplate", "pt");
c.setProjection(Projections.distinct(Projections.property("pt.id")));
List<Object> objects = c.list();
上一篇:java-休眠条件,整数和“喜欢”


下一篇:java-具有Spring Data Pageable的JPA Criteria查询总和