File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes fetching data :: eager Vs lazy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "fetching data :: eager Vs lazy" Watch "fetching data :: eager Vs lazy" New topic

fetching data :: eager Vs lazy

satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Using JPA ( with underlying provider as Hibernate )
This fetch mode is defined in the association annotation itself

This means that in the client that makes use of this code is stuck
The behaviour is fixed .

Istnt that a disadvantage ?
Can I not change it dynamically based on what client wants ?

There very well could be scenarios that for a user A I only have 2-3 records as addresses and for User B I have 100 records as addresses

I want to do a eager load of data for User A and a lazy load for user B .

Thanks ,
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Which is why the default is to load lazy. So that only on use case do you say I want that eager. In creating Query objects you can then set the association to eager load. It should always be use case driven and not one default to rule them all.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: fetching data :: eager Vs lazy
It's not a secret anymore!