LAZY is the default fetch type for all Hibernate annotation relationships. When you use the Lazy fetch type, Hibernate will not load relationships for this particular instance of the object. So what is the difference between Eager and Lazy?
The Eager extraction type, in fact, is the opposite of Lazy, by default, Eager loads ALL relationships associated with the specific object loaded by Hibernate. That means if you change your relationship to be that

Hibernate will now load the user profile into the default user object. This means that if you access user.getUserProfile (), it will not be NULL (unless the join table actually contains a matching row for the connection column user_profile_id).
So, a short story here:
FetchType.LAZY = Does not load relationships unless explicitly βrequestedβ through the retrieval method FetchType.EAGER = Loads ALL relationships.
Pros and Cons If using a delayed loading approach can throw NullPointerException, then why the hell would you want to use it? Ok, let's wait a minute to think about it.
Suppose we had a User object that has 10 different relationships with other objects. Let's also assume that you have a user who is trying to log in, and you just want to check if their username and password match what is stored in the database. Are you sure you want to download ALL 10 relationships and DO NOT use ANY of these downloaded relationships? Remember that loading things from the database is quite "expensive" in terms of the time required to load all this information into Java objects and store it in memory. And what happens if one of the relations points to an object that ALSO has 10 relations (and all of them are configured as the EAGER fetch type). Think of the cascading killing of objects loaded from a database into memory!
The way I would put it this way:
EAGER: comfortable but slow
Lazy: more coding, but much more efficient
Tharana mayuranga
source share