This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Lazy loading in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Lazy loading in JPA" Watch "Lazy loading in JPA" New topic
Author

Lazy loading in JPA

Ashwin Pai
Ranch Hand

Joined: May 20, 2008
Posts: 90
Hi All,

I have a question about lazy loading...
I have the following relationship
1 Book has 0..* Reviews.

Scenario is
User searches for books. And then clicks on the book of interest. The system should display all the Reviews for the books.

I am using JPA and I have modelled my Book class to have a List<Review> objects.
I have annotated Reviews as a lazy load.

Now when user searches for books, I use a named query for searching the books. As per my understanding of lazy load, the reviews will not be loaded.
Now these Book entities are serialized and passed to the presentation tier and displayed using jsp. Once the user clicks the book of interest I want to load the reviews for the book.
Will the reviews be loaded if I refer the member ? or Do i have to use the EM to get the reviews using named queries ?

Thanks
Ashwin


The only way to make your dream come true is to wake up.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Ashwin,

What is your persistence provider?

Regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Ashwin Pai
Ranch Hand

Joined: May 20, 2008
Posts: 90
Originally posted by Reza Rahman:
Ashwin,

What is your persistence provider?

Regards,
Reza


Hi Reza,
I am in the process of creating class diagrams & sequence diagrams for SCEA assignment. I was not sure if lazy loading is implemented differently by different vendors!!! I would like to design something which is not provider dependent..if thats why raised the question!!
So would it make sence to make the reference to Reviews transient and have it loaded through named queries ?

Aprreciate your time!!

Thanks
Ashwin
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Ashwin,

Lazy loading behavior outside an active transaction is currently vendor dependent.

Regards,
Reza
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lazy loading in JPA