HQL how to join three table

 ̄綄美尐妖づ 提交于 2020-01-23 01:33:06

问题


I Have this classes:

 @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;
}

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.


回答1:


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=?

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



来源:https://stackoverflow.com/questions/20570351/hql-how-to-join-three-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!