• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

When to use find() vs load ?

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Scott.
 
reply
    Bookmark Topic Watch Topic
  • New Topic