Using Left Joins in HQL on 3 Tables

后端 未结 2 1627
鱼传尺愫
鱼传尺愫 2021-02-05 16:17

I have three tables A B and C. Now i want to execute this sql query in HQL:

select * from A as a 
left join 
B as b 
on 
a.id = b.id 
left join 
C as c 
on 
b.t         


        
相关标签:
2条回答
  • 2021-02-05 16:28

    I suppose you've already defined all the needed associations in your configuration. If so, in HQL it would look like this:

    from A as a left join a.B as b left join b.C as c 
    

    There is no "ON" statement in HQL, hibernate does automatically based on your mappings and defined Associations.

    Pay attention to a.B and b.C.

    You refer to B and C based on already defined aliases a & c.

    0 讨论(0)
  • 2021-02-05 16:36

    Use this query

    from A as a
    left join fetch a.B as b 
    left join fetch b.C as c 
    
    0 讨论(0)
提交回复
热议问题