load() vs. get()
1. Return value, if ID not found
- load() method will throw an exception if the unique ID is not found in the database.
- get() method will return null if the unique id is not found in the database.
2. Fetch technique
- load() just returns a proxy or make a database hit if any other method than getId() is called
- Lazy initialization ; offers better performance - get() will initialize the full objects using n number of database hits, if object could not found in session cache.
3. Use case
- Only use the load() method if you are sure that the object exists.
- If you are not sure that the object exists, then use one of the get() methods.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.