What is the difference between eager and lazy? when I use them an entity Manager retrieve the entities of a database?
What is the difference between eager and lazy? when I use them an entity Manager retrieve the entities of a database?
The difference between eager and lazy can be seen when you have 2 related entities. For example, if you have an entity called City, and another inhabitants ... The city entity has basic properties such as Id, name, surface, just as the entity has its own.
When java loads the entity City, it loads those basic properties, but for inhabitants you have 2 options. Load all the inhabitants of that city (eagerly) or go loading the inhabitants on demand (lazy) when for example you call a function such as GetHabitantes ().
As you can see, it's a matter of efficiency, because if you do not need to see information about the inhabitants, it would be a waste to load all the data of those inhabitants initially.