There are following difference between get() and load() method in Hibernate.hibernate Session class provides these two method to access object.
session.get() |
session.load() |
get() method will hit the database if object is not found in the cache and returned completely initialized object, which may involve several database call. |
load() method can return proxy, if object is not found in cache and only hit database if any method other than getId() is called. |
get() method returns null when records against the id isn’t found in the database. |
load() methods throws ObjectNotFoundException if the required records isn’t found in the database. |
get() method is not give better performance than load() method. |
load() method use only when we are sure about existence of records against an id. |
get() method is used to retrieve a persistent object from the database. |
load() method give better performance because it support lazy loading. |