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

Load() method:
  • Only use the load() method if you are sure that the object exists.
  • load() method will throw an exception if the unique id is not found in the database.
  • load() just returns a proxy by default and database won't be hit until the proxy is first invoked.

Get() method:

  • If you are not sure that the object exists, then use one of the get()methods.
  • get() will hit the database immediately.
  • get() method will return null if the unique id is not found in the database.

Search:

Recent Posts