Hibernate: Overriding mapping's EAGER in HQL?

前端 未结 2 1175
时光取名叫无心
时光取名叫无心 2020-12-14 09:19

It\'s possible to override LAZY in HQL using LEFT JOIN FETCH.

FROM Obj AS obj LEFT JOIN FETCH obj.otherObj WHERE obj.id = :id
         


        
2条回答
  •  既然无缘
    2020-12-14 09:44

    The qualifier in this snippet from the Hibernate Docs implies that you can override lazy with eager, but not the other way around:

    If you are using property-level lazy fetching (with bytecode instrumentation), it is possible to force Hibernate to fetch the lazy properties in the first query immediately using fetch all properties.

    Unusually, it looks like you can if you use the Criteria API to go from eager to lazy. Just call setFetchMode(FetchMode.LAZY) on the relevant join.

提交回复
热议问题