File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes lazy loading not working in hibernate 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "lazy loading not working in hibernate 3" Watch "lazy loading not working in hibernate 3" New topic
Author

lazy loading not working in hibernate 3

kishore mang
Greenhorn

Joined: Nov 27, 2012
Posts: 10
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

Joined: Aug 06, 2012
Posts: 122

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

Joined: Nov 27, 2012
Posts: 10
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

Joined: Aug 06, 2012
Posts: 122

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

Joined: Nov 27, 2012
Posts: 10
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lazy loading not working in hibernate 3