Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lazy loading not working in hibernate 3

 
kishore mang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,









and my entity objects:





when i run following statement it fetching child/referenced objects too which i dont want






any suggestions where things going wrong? please suggest.

Regards
Kishore
 
Kathleen Angeles
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you get the data you used to print below?



If it is from the same 'event' object instance returned by hibernate, and if at that moment that object is still managed by hibernate, you will inadvertently load the data.
 
kishore mang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathleen,

appreciate for your quick response, even i removed toString() in all classes still able to see
in debug view the event object and its all child objects loaded with all values set.

So i am sure that returned session.get() which is event is loaded all its child objects.
This means eclipse debug view loading all referenced child objects?

Regards
Kishore
 
Kathleen Angeles
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible that is the eclipse debug mode that loads it.

Quite dirty, but just to see that those data are really lazily-loaded: disable the debug mode of eclipse, after getting the 'event' object from hibernate, terminate or close the hibernate session, then try display the supposed-to-be lazily-loaded data. You should get an exception or null, showing that it was never loaded by hibernate.
 
kishore mang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right!!!
after session closed in eclipse debug mode i can see message about all referenced objects
as "com.sun.jdi.InvocationException occurred invoking method", means referenced data not loaded.

i never expected that eclipse debug mode causing referenced data get loaded by parent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic