• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How lazy loading is working in JPA

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have one doubt regarding Laxy loading of the objects in JPA. Let us suppose i have one entity Class A. A is mapped with one to many with B and B is mapped with C as Many to one. Below is sample class struture.

A {

@OneToMany(FetchType=Lazy)
private List<B> blist;
}

Class B

public class B {

@oneToMany(FetchType=Lazy)
private List<C> clist;

My question
1. B is defined as Lazy in A. Now if i will do entityManager.find(A), it will not load the data from B as due to Lazy. If i have made it Eager and they try to load entity A. then It should have to load entity of B also. Now C is defined as Lazy in B. Will it fetch data for entity C also in above case.

Regards,
sunil
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No it will probably will not. Remember that using the fetchtype to lazy is only a hint. It is not enforcing. The JPA provider might decide to load it anyway. If you set the fetchtype to eager then the provider must load it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic