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 How lazy loading is working in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How lazy loading is working in JPA" Watch "How lazy loading is working in JPA" New topic
Author

How lazy loading is working in JPA

xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
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
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
jQuery in Action, 2nd edition
 
subject: How lazy loading is working in JPA
 
Similar Threads
Lazy loading exception in presentation layer, what's the nicest way to avoid them?
How does JPA/ORM know the target entity?
Heap exception while loading complete table data from database
Basic JPA @OneToMany / @ManyToOne mapping trouble (related to hibernate?)
List query annotation ?