views:

30

answers:

2

Looking for a really good article that includes strategies/bugs/workarounds. I would prefer a pure JPA solution but I know Hibernate offers a lot of extensions.

A: 

I'm not sure of what you're looking for exactly. But to put is simply, LAZY simply means that a child association won't be loaded while loading the parent, it will be loaded when explicitly asked by the application. EAGER means that a child association will be loaded while loading the parent.

In general, LAZY is better performance wise (when you just don't need or want to load a whole objects graph). But depending on the situation, it might just be suboptimal or lead to the famous "N+1 SELECT" problem (while iterating over a list of N entities, accessing a LAZY association will fire another SELECT, resulting in 1+N SELECT at the end). Depending on the situation, an EAGER association - or a FETCH JOIN to prefetch the association - is preferable.

So I don't know what part is unclear but here are some resources that might help:

See also:

Pascal Thivent
The concepts are clear, I'm looking for a discussion of strategies. I'll check out your links, tnx.
Chance Kunga
A: 

Book "Java Persistence with Hibernate" by Bauer and King, Chapter 13 "Optimizing fetching and caching". You should be able to find a copy of the book online.

grigory