aspose file tools*
The moose likes Object Relational Mapping and the fly likes Want to know practically when to use GET method and when to used LOAD method of hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Want to know practically when to use GET method and when to used LOAD method of hibernate?" Watch "Want to know practically when to use GET method and when to used LOAD method of hibernate?" New topic
Author

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

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30516
    
150

Read this for the differences.

As far as CRUD, they both go with the R or read operation.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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.

True person is moral, false is right!
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to know practically when to use GET method and when to used LOAD method of hibernate?