HQL如何加入三个表 [英] HQL how to join three table

查看:180
本文介绍了HQL如何加入三个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个课程:

 @Entity
 public class Category {
    private Long Id;
    private String name;
    private String description;
    private List<Product> products;
}

@Entity
public class Inventory {

    private Long id;
    private Product product;
    private int quantity;
}

@Entity
public class Product {
    private Long productId;
    private String name;
}

我想在类别中获得给定ID的库存。我正在尝试使用此

I want to get the Inventory given the id in the category. i'm trying to use this

return session.createQuery("select i from Inventory i, Category c join c.Products p outer join i.product = p WHERE c.Id=?")
                .setParameter(0, categoryId).list();

我真的很困惑,请帮忙。谢谢。

I'm really confused, please help. Thanks.

推荐答案

好吧没关系,我发现了怎么做

Alright nevermind, I found out how to do it

Select i from Inventory i,Category c INNER JOIN i.product ip INNER JOIN c.products cp where ip = cp and c.id=?

所以我实际上想知道如何将类别与连接相关联,我在多态查询下找到了答案在HQL文档中

So I was actually wondering how to relate the Category to the joins, I found the answer under Polymorphic queries in HQL documentation

这篇关于HQL如何加入三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆