What is the difference between Hibernate get() and load() methods?

What is the difference between Hibernate get() and load() methods?

Ninja Asked on 17th September 2018 in Hibernate.
Add Comment
1 Answer(s)
Best answer

Hibernate session’s get() method is used to retrieve an object from the database using a unique Id. The method returns null if the object is not found in the database. If the object is not available in cache, but exists on database, it may involve several data access calls to database returning a completely initialized object.

Hibernate session’s load() method is also used to retrieve an object from the database using a unique Id. However this method throws an exception if the object is not available in the database. If the object is not available in cache, but exists on database, load() method can return proxy in place providing lazy initialization which results in better performance.

Ninja Answered on 17th September 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.