JPA_and_Hibernate

Difference between Get and Load in Hibernate

Posted On
Posted By admin

In this blog post, I will be explaining the difference between the Hibernate load and get methods.  Both methods are used to load a record corresponding to an id. However, there are some differences between the two. 

 

LoadGet
If there is no record in the database corresponding to the id passed in, the load method throws an exceptionIf there is no record in the database corresponding to the id passed in, the get method returns a null
When the load method is used, it returns a proxy object with just the id field populated. All other fields are blank. The fields are only fetched from the database when they are accessed from the code. When the get method is used, it fetches the complete object i.e. it fetches all the fields of the object.

 

If you'd like to watch a detailed video tutorial of this topic or other related topics, do check out my Hibernate course Hibernate from scratch

If you like this post, please do let me know via the comments box below.  You can also connect with me via my Facebook Page or subscribe to my Youtube channel!

Related Post

leave a Comment