1. Compare the results from the return:
A Org.hibernate.ObjectNotFoundException exception is thrown if the load method is not retrieved
The Get method returns null if it is not retrieved
2. Comparison from the search execution mechanism: Both the Get method and the Find method are retrieved directly from the database and the execution of the load method is more complex first to find out if there is a cache in the persistent context of the session, and if so, if not, to determine whether it is lazy , if you do not directly access the database retrieval, find the record returned, cannot find the throw exception if it is lazy need to establish a proxy object, the object's initialized property is the False,target property is null when accessing the obtained proxy object's properties, retrieve the database, If a record is found, the object of the record is copied to the target of the proxy object, and the exception is thrown if the initialized=true is not found.
3. Fundamental difference Description
If you use the Load method, hibernate considers that the object (database record) corresponding to the ID must exist in the database, so it can be used with confidence, and it can safely use the proxy to delay loading the object. The database is queried for other property data in the object, but in case the record does not exist in the database, there is no way to throw an exception. The Load method thrown exception refers to throwing exceptions when the data is not present in the database when the object is being used, rather than when creating the object (Note: This is because of "lazy loading" in mischief).
because the cache in the session is a fairly inexpensive resource for Hibernate, the session cache is checked at load to see if the ID corresponds to the existence of the object, and the proxy is created if it does not exist. So if you know that the ID must have a corresponding record in the database, you can use the Load method to implement lazy loading.
get method first queries the session cache, does not query the level two cache, and finally queries the database; Instead, the Load method first queries the session cache, does not create the proxy, and queries the level two cache and database when the data is actually used.
4. Brief summary
In short, for get and load the fundamental difference, in a word, hibernate for the load method that the data in the database must exist, can be assured that the use of agents to delay loading, if the use of the problem found in the process, can only throw exceptions, and for the Get method, Hibernate must obtain the actual data, otherwise null is returned.
Hibernate Get and load differences