A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Databases
»
Object Relational Mapping
Author
fetching data :: eager Vs lazy
satish bodas
Ranch Hand
Joined: Jun 19, 2008
Posts: 116
posted
Aug 11, 2008 01:56:00
0
Using JPA ( with underlying provider as Hibernate )
This fetch mode is defined in the association annotation itself
@OneToMany(mappedBy="user",cascade=CascadeType.ALL,[B]fetch=FetchType.EAGER[/B]) public Set getAddress() {
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 ,
~satish
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17234
1
I like...
posted
Aug 12, 2008 09:29:00
0
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.
Mark
Perfect World Programming, LLC
-
Two Laptop Bag
-
Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: fetching data :: eager Vs lazy
Similar Threads
How lazy loading is working in JPA
@OneToMany problem with complex PK
OneToOne Lazy-load
What are Lazy fetching and Early fetching?
Fetching a reference in an entity which is no longer managed
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter