Explain the difference between load() and get() in Hibernate.Difference between load() and get():
load() :
1. Use this method if it is sure that the objects exist.
2. The load() method throws an exception,when the unique id could not found in the database.
3. The load() method returns proxy by default and the data base will not be effected until the invocation of the proxy.
get() : 1. Use this method if it is not sure that the objects exist.
2. Returns null when the unique id is unavailable in the database.
3. The data base will be effected immediately.Explain the difference between load() and get() in Hibernate.1. Session.get() returns a fully initialized instance which is fully available in any future detached state.
2. This was actually aligned in Hibernate3 with the EntityManager.find() operation, which has been standardized that way.
3. Session.load() or EntityManager.getReference() should be used if a fully initialized instance is not needed, which saves a database roundtrip if nothing other than creation of an association is done, with the proxied instance in managed state.
4. The instance data is then not available fully in detached state.
5. If working with detached objects is not needed, load() or getReference() can be used to get the extra optimization of proxies in Hibernate.
-load() should be used only if an object exists else using get() is appropriate. -load() throws an exception if the unique id is not found in the database while get() returns NULL. -load() returns a proxy by default and database won’t be hit until the proxy is first invoked while get() will hit the database immediately.
|