• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Want to know practically when to use GET method and when to used LOAD method of hibernate?

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a confusion.I have searched and seen difference between GET and LOAD.(Load method does not hit the database).However I want to know practically when to use GET method and when to use LOAD method.E.g in common CRUD operations of hibernate I have seen people using Load method too.So I want to know

a) Example of cases where GET method is used.

b) Example of cases where LOAD method is used.

Since most of common operations are CRUD operations it will be easier to understand a) and b) with their involvement in common CRUD operations.

Thanks.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this for the differences.

As far as CRUD, they both go with the R or read operation.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.I read the difference in the blog. On choosing between the two it says:

"If you’re certain the persistent
object exists, and nonexistence would be considered exceptional, load() is a
good option. If you aren’t certain there is a persistent instance with the given
identifier, use get() and test the return value to see if it’s null"


I still have doubt. If I have an application with User objects.To display these which approach will I use:

a) use query "from User"
b) Use get method.
c) Use load method.
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are sure you need to use properties of User object then use hibernate's get method.
If you see that user's properties might be used or might not be used then hibernate's load method because it goes to db only if you want to access any property except identifier.

Use HQL when you need to do your own custom query which is not provided by hibernate. I read it is better to use Named Queries.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you are sure you need to use properties of User object then use hibernate's get method.
If you see that user's properties might be used or might not be used then hibernate's load method because it goes to db only if you want to access any property except identifier.

Use HQL when you need to do your own custom query which is not provided by hibernate. I read it is better to use Named Queries



Thanks a lot.This one is the exact answer to what confusion I had.
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic