• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load and Get

 
Sangeetha deshpande
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the diffrence between load and get?


Thanks in advance
Sangeetha
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the javadoc of Session-

"load" method:

Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.

You should not use this method to determine if an instance exists (use find() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.


whereas "get" method:

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.


So, load is going to throw an error if the object for a given id does not exist whereas get is just going to return null, in such a case.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think get will also be returning a proxy object. whereas load wanted to load the data, and that is one of the reasons why it needs to throw an exception.

Or it could be the other way around.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic