get() vs load()

Differences between get() and load()

1. In hibernate get() method can be used to retrieve a record from database table if the record is existed. If the required record is not existed then get() method will return null value.

public Object get(String class_Name, Serializable pk_Val)
public Object get(Class class_Type, Serializable pk_Val)

load() method can be used to retrieve a record from database table if the record is existed. If the required record is not existed then load() method will rise an Exception like HibernateException.

public Object load(String class_Name, Serializable pk_Val)
public Object load(Class class_Type, Serializable pk_val)

2. get() method is able to perform eager or early loading, that is, it will interact with database directly and it will retrieve data and return to Hibernate application in the form of Object on the method call.

load() method will perform Lazy or late Loading , that is, when we access load() method then a duplicate object will be created with the primary key value without interacting with database. When we use other properties of the Object then only it will fetch data from database table and return that data to Java application.

get() vs load()
Scroll to top