Comparison
Lazy loadingvsVirtual proxy
Lazy loading
you looped over a hundred orders reading customer.name, and the log showed a hundred and one queries.
Deferring the loading of an associated object until it is first accessed, usually through a virtual proxy or a marker on the field. It makes a naive read cheap and makes the cost of a loop invisible, which is the entire mechanism behind the N+1 query problem. It also produces the other classic failure — touching a lazy field after the session has closed, which fails at a point far from the query that caused it.
Full entry →Virtual proxy
you had an object with an id and nothing else, and touching any other property fired a query.
A proxy that stands in for an expensive object and creates or loads it on first real use. It is the mechanism behind ORM lazy loading and behind placeholder objects in graphics and document systems. Its characteristic problem is that the cost is invisible at the call site, which is precisely how the N+1 query gets written by someone who thought they were reading a field.
Full entry →