This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes is LAZY loading  guaranteed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "is LAZY loading  guaranteed?" Watch "is LAZY loading  guaranteed?" New topic

is LAZY loading guaranteed?

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201
Hello to all,

We have in our application the list of the documents(pdf,doc,xls) for the users to see. Also the use can upload the documents and search the documents. Now for the documents contents field I used LAZY loading so that when the list of the documents is presented to the user the contents of the documents should not be fetched. ONly when the documents link is clicked the contents be fetched.

But while navigation between different pages of documents I do not see considerable increase in performance of the application. It slows down when say in the upcoming list of the documents contents large documents.

How do I know that for a particular document or for all the documents lazy loading is performed. I mean how do I know tha contents are not loaded for the document.

I have read somewhere that LAZY loading is not guaranteed. I am using eclipselink.
Thanks and Regard,
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
With EclipseLink JPA you can enable SQL logging by setting the persistence.xml property,


This will give you a better idea of what is occurring.

In EclipseLink LAZY for OneToMany of ManyToMany is always supported. LAZY for OneToOne or ManyToOne requires that you use the EclipseLink agent is JSE (-javaagent:eclipselink.jar), or occurs automatically in JEE (provided the JEE server correctly supports EJB3). You can also use static weaving using the ant task provided by EclipseLink.

Note that EclipseLink enables caching by default, so if your object is already in the cache, you will not see any database access.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: is LAZY loading guaranteed?
It's not a secret anymore!