(Lazy) LEFT OUTER JOIN using the Hibernate Criteria API

前端 未结 3 1079
一生所求
一生所求 2020-12-28 15:44

I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method:

Criteria crite         


        
相关标签:
3条回答
  • 2020-12-28 15:58

    Sdavids answer's API is deprecated now. Its updated version is

    ....createAlias("employee", "emp", JoinType.LEFT_OUTER_JOIN)

    0 讨论(0)
  • 2020-12-28 16:21

    If you need to left join on the products table just do:

    .....createAlias("products", "product", Criteria.LEFT_JOIN);

    0 讨论(0)
  • 2020-12-28 16:22

    A join is in the SQL request. It can't be lazy.


    With Hibernate, to retrieve lazily this data, just exclude it from the HQL request. Then, when you access the getters on your entity (if your Session is still open), it will be loaded automatically (you don't have to write that part of the request).

    0 讨论(0)
提交回复
热议问题