R – In an ORM, does “lazy loading” mean you may not get the results you expect from larger columns

databaselazy-loadingorm

I was reading about a feature of an ORM called lazy loading, which, it said, means that larger columns are only loaded when the application actually needs them. How would an ORM decide what a "large column" is – would this be, for example, a blob column that can contain a lot of data compared to, say, an unsigned integer column? And when it says it lazy loads the column, does this mean when you run a query, you might not get results for some of the larger columns when you expect to?

Best Answer

In NHibernates case, lazy loading is preventing the loading of collection properties on the object (normally by joining another table, or sub selecting) until you access the collection property.

For example, you might want to load all the customers, but if the customers had an orders property (collection of orders), you can load all the customers without the orders, and then lazy load the orders of a specific customer when you want to see the orders.

This saves many database calls when you do not necessarily need all the data up front.

Related Topic