aspose file tools
The moose likes Object Relational Mapping and the fly likes When to use find() vs load ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "When to use find() vs load ?" Watch "When to use find() vs load ?" New topic
Author

When to use find() vs load ?

Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Hi,

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
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.
Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Thanks Scott.
 
IntelliJ Java IDE
 
subject: When to use find() vs load ?
 
Threads others viewed
jQuery load with Callback
Getting Values of Parameters to Method
Help understanding when to use em.find and query manager and their ability to fetch nested objects
jsp response time
HFSJ 2 ed. Final mock exam 43 question
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture