Eduardo Bueno wrote:You don't want to use lazy initialized collections? Then just define them as FetchType.EAGER. If you want a better approach, you can use them lazy implementing OpenSessionInView pattern, which will load them once you try to access it in code. I don't know if it can be implemented without hibernate, though.
ben win wrote:
Eduardo Bueno wrote:You don't want to use lazy initialized collections? Then just define them as FetchType.EAGER. If you want a better approach, you can use them lazy implementing OpenSessionInView pattern, which will load them once you try to access it in code. I don't know if it can be implemented without hibernate, though.
FetchType.EAGER is fine when loading entities via Session#get(), but its ignored when using HQL or Criteria.
If you dont want lazy collections on entites loaded by Criteria or HQL you have to explicitly JOIN FETCH them.
Eduardo Bueno wrote:
ben win wrote:
Eduardo Bueno wrote:You don't want to use lazy initialized collections? Then just define them as FetchType.EAGER. If you want a better approach, you can use them lazy implementing OpenSessionInView pattern, which will load them once you try to access it in code. I don't know if it can be implemented without hibernate, though.
FetchType.EAGER is fine when loading entities via Session#get(), but its ignored when using HQL or Criteria.
If you dont want lazy collections on entites loaded by Criteria or HQL you have to explicitly JOIN FETCH them.
That is not true, the only way objects are not fetched is with plain SQL.
Prefer lazy fetching for associations.
Use eager fetching sparingly. Use proxies and lazy collections for most associations to classes that are not
likely to be completely held in the second-level cache. For associations to cached classes, where there is an
a extremely high probability of a cache hit, explicitly disable eager fetching using lazy="false". When an
join fetching is appropriate to a particular use case, use a query with a left join fetch.