Hibernate - HQL to fetch a collection from Unidirectional OneToMany relationship

后端 未结 2 1294
自闭症患者
自闭症患者 2021-02-08 23:14

I have an Class with a unidirectional one to many relationship as follows:

public class Order {
    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name=\"o         


        
2条回答
  •  太阳男子
    2021-02-08 23:45

    It sounds like you want to map the other side of this relationship i.e. make this bi-directional mapping.

    Then you can use the order number in your HQL:

    from Item as item where item.amount > :amount and item.order.id = :orderId
    

    From the HQL documentation:

    from Cat as cat where cat.mate.id = 69 The query is efficient and does not require a table join.

    The fact that you are trying to do this query suggests that the relationship between a Line and its Order is important!

提交回复
热议问题