What is the opposite of lazy loading? - lazy-loading

Is there a common term / catch-phrase for the opposite of lazy loading?

The oposite term for lazy loading is eager loading.
Eager loading is essentially computing the tasks when you ask for it.
Lazy Loading is when you only do the computation when it is required.

I've seen the terms "Eager Loading" and "Aggressive Initialization" both used.

I'd say that the opposite of lazy is proactive loading, i.e. loading something in advance, before it's really needed.
However it's hard to pick the opposites when you have 3 entities {lazy, eager, proactive}

Related

fluent nhibernate: set lazy loading in execution time?

is it possible in Fluent NHibernate to enable or disable Lazy loading in execution time?
In some cases when I retrieve an object I need the Many relation to be lazy loaded and in other cases I don't want.
Thanks in advance
Short answer: no.
You should map the association as lazy (this is the default), and when required, use a fetch load query.

Extbase: Choose lazy or eager loading at runtime

I have a domain object Foo that has an 1:n relation to a domain object Bar.
There are two major use cases where I need to get all foo's matching some criterion. In case A, I care about the bars attached to each foo, in case B, I don't. There are quite a lot of bars, so simply always loading the bars is not good for performance of case A. Similarly, not loading the bars eagerly will lead to an n+1 avalanche in case B. So neither tagging the realtion as #Lazy nor not tagging it is the correct choice.
Now, my question: Is it possible to tell the extbase persistence layer at query time whether to be lazy or eager? If yes, how? If no, is there another way in Extbase to avoid the n+1 problem (i.e. load all necessary bars and then hope that caching works when iterating through the foos)?
My last resort, of course, would be to load the foos with lazy loading, load the bars manually in a second query, and then manually set the relation.
Any suggestions?
I've been playing around with Extbase and delving into the internals in the last few months, and the upshot is this: It' impossible.
I suppose that closes this question, though not the way I'ld like.
Actually, even worse: Eager loading is not implemented at all, the #eager tag which according to the documentation sets eager loading for a relation is ignored.
what about leaving it lazy and converting it to an array when needed? (foo->bar->toArray())

In Doctrine 2 can the Fetch Mode (Eager/Lazy etc.) be changed at runtime?

I have entities which I would like to eagerly load , and on other ocassions lazy (or even extra lazy) load.
My mappings have no fetch mode declared in my YAML- so they use the default (lazy loading).
Currently the only way to eagerly load is to by constructing the DQL manually - and I need to update this every time I add a new entity.
Ideally I would just load the root entity and the force eager loading all the associated objects. Is there any way I can do this?
If not why (is there a reason beyond it being an unimplemented feature)?
If you want to use built-in repository methods (find(), findAll()), you're probably out of luck unless you set things to eagerly load in your annotations.
You'll probably want to use the query builder (or raw DQL) in some custom repository's method to force eager loading where you want it. Yes, you'll have to update that method as you add entities, but at least you'll always know what's going on in regards to lazy/eager loading, and you'll only need to maintain it all in one place.
I suppose the reason there's not some $eagerLoad flag to find(), etc, is because those are convenience methods for simple tasks. If you wanted to add such a flag, you'd have quickly get into situations where you'd want to limit recursive eager loading by depth. You'd also probably have to start worrying about cyclical references (any bidirectional association, for instance).
You can use setFetchMode() method of DQL to set mode.
See the documentation:
https://web.archive.org/web/20120601032806/http://readthedocs.org/docs/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html

HIbernate - bulk loading child objects

How can I get NHibernate to hook up child objects automatically or bulk load children rather than lazy loading for each parent?
I have a large number of parent objects all of the same type. Each of them has two bags of child objects. As I need to load all the parents and children objects as quickly as possible, I use NHibernate to load all the objects and then loop all child objects and add them to relevant parent in code. I'm sure NHibernate has a much better way of doing this - but what is it?
You can always use eager loading behavior of NHibernate to override its default behavior (Lazy Loading).
Here is an article that discuss lazy loading and eagerly loading
Take a look at the "Eagerly loading with HQL" part that shows how you can use HQL to eagerly load an object graph.
However using eager loading can have a negative impact on performance specially if you are working with a lot of objects.

When must we use eager loading in NHibernate? What is it's usage?

When must we use eager loading in NHibernate? What is it's usage?
One usage is when you will cache or store an object graph (in ASP.NET Cache for instance). If you don't store the whole graph, you would be missing information on a detached object. You can reattach objects of course, but that would probably be a new roundtrip to the database anyway.
If you don't eager load your collections, you would need to touch every one of the to invoke the lazy fetch. In those cases, an eager fetch is much more useful.
Maybe this presentation by Udi can help you decide.
http://www.infoq.com/presentations/Making-Roles-Explicit-Udi-Dahan