Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No difference in output for load and get  RSS feed

 
raja singh kumar
Ranch Hand
Posts: 186
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying a simple example to see the difference between load and get in hibernate. Actually I am expecting the load method to load lazily but the load method also does eager loading. Where is the mistake?



Output:
Before get
Hibernate: select student0_.id as id1_1_0_, student0_.name as name2_1_0_ from Student student0_ where student0_.id=?
student getid2
student getNamename2
After get
Before load
Hibernate: select student0_.id as id1_1_0_, student0_.name as name2_1_0_ from Student student0_ where student0_.id=?
student getid:1
student getName:name1
After Load




 
Dave Tolls
Ranch Hand
Posts: 2826
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing in that object that is lazy-loadable.

Your Student appears to only have 2 fields, id and name.
Lazy loading is around loading relationships.
 
raja singh kumar
Ranch Hand
Posts: 186
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I dont want any relationships. The examples I referred are doing the same thing which I am doing but they get different output for get and load which is mentioned as the difference between get and load.

Can you post a simple example to show the difference between get and load?

Also, I am not sure if the difference between get and load is same as the difference between eager loading and lazy loading. If somebody could throw some light on it.
 
Dave Tolls
Ranch Hand
Posts: 2826
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a link to the examples that show a different output?
Or could you post them here (with associated credit for where they came from)?

The API for Session.load says:

This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.


Note the "might".
I don't know what drives that, offhand.
 
raja singh kumar
Ranch Hand
Posts: 186
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I post  similiar examples from some random tutorial site which may not be authentic or certified?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, just make sure you provide links to those sites.
 
raja singh kumar
Ranch Hand
Posts: 186
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are couple of examples which show there is difference in the output of get and load. But I am unable to replicate it. Can anyone post a program which shows there is a difference in the way get and load works?

http://www.java4s.com/hibernate/difference-between-hibernate-get-and-load-methods/
http://www.journaldev.com/3472/hibernate-session-get-vs-load-difference-with-examples
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!