Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Monica Shiralkar
Ranch Hand
Posts: 861
1
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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: 861
1
  • Mark post as helpful
  • send pies
  • 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.
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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: 861
1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic