Hibernate has methods for finding - find() and loading load(). In my opinion, correct me if i am wrong, both do the same task. Find that record and then return it. I am unclear when we should use the find() method versus the load() method.
Thanks, Gayatri
Scott Johnson
Ranch Hand
Joined: Aug 24, 2005
Posts: 518
posted
0
Here are a few of the differences, read the Hibernate reference for more details.
To use load() you need to know the object's identifier. If the object doesn't exist, load() throws an exception. load() returns a single entity.
get() takes an identifier and returns a single entity. It returns null if an object with that identifier is not found.
find() takes an HQL query instead of an identifier and returns a list of entities. (I think find() is deprecated in Hibernate 3.)
list() is similar to find() except it accepts parameters using a QueryParameters object instead of arrays and can accept a Criteria object as well as a String with HQL.