gpt4 book ai didi

java - 如何在Hibernate中实现多重inner join

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:55 25 4
gpt4 key购买 nike

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 - 如何在Hibernate中实现多重inner join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16956052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com