views:

321

answers:

1

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

Is it also possible to override EAGER? How?

+1  A: 

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.

sblundy