Primary difference between get and load is,
load():
- It creates a proxy of that object using the given Id instead of fetching the row from the database. It works on the Lazy loading phenomenon, you will get the actual object once after you tries to get the object members. That’s why if you are using load() then be aware because out of the session boundary you won’t be able to get the other details of that object if details were not fetched with in the session boundary.
- Throws ObjectNotFoundException if data is not found in first cache and second in DB.
User user = (User) session.load(User.class, userID);
get(): return the real
object, an object that represent the database row, not proxy. If no row found ,
it return null.
User user = (User) session.get(User.class, userID);
No comments:
Post a Comment