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 as expected 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 as expected" Watch "Lazy loading not working as expected" New topic
Author

Lazy loading not working as expected

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
I am making use of hibernate3 and having the following code



Hibernate3 has lazy as true by default. I am executing the following code.



When the line



is executed, I get the following sql in my console



The first SQL is fine, but in case of 2nd query, the attendees is being fetched when the event method is called.
Accoring the lazy loading, it should not load the object when event is being accessed. Why is 2nd and 3rd SQL fetching the associated objects.

SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
I figured out the problem. My config files were not using hibernate3, since it had wrong entry.

Old config file entry


New config file entry



On making use of new config file entry, the lazy loading works as expected.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Lazy loading not working as expected