Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

No difference in output for load and get

 
Ranch Hand
Posts: 212
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




 
Rancher
Posts: 4603
47
  • 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: 212
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
Rancher
Posts: 4603
47
  • 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: 212
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?
 
Marshal
Posts: 25669
69
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: 212
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
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic