Imagine you have a group of users. Every user has a set of events to attend.
Code:
User
- Set Events
User
- Set Events
User
- Set Events
If you apply lazy initialization, it means that you can list all the users, without initializing the Events for each user. It would look like this:
Code:
User
- Set events (uninitialized)
User
- Set events (uninitialized)
User
- Set events (uninitialized)
This is used for performance reasons. It is also a logical feature, because you don't need information about the events, if you ask information about the users.
Whenever you want information about the events, hibernate will lazy-load (right on time, when you want it) the events about that user. So imagine you want information about the events of user 1. It will look like this:
Code:
User
- Set events (initialized)
- - Event 1
- - Event 2
- - Event 3
- - .......
User
- Set events (uninitialized)
User
- Set events (uninitialized)