Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what are the disadvantage of Lazy and eager fetching??

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the disadvantage of Lazy and eager fetching??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to be rude, but have you read the documentation? Its pretty clear on these topics. Rather than simply repeat what that say here I recommend you go and have a read.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, eagar fetching can give you more data than you need and cause inefficiencies. Alternatively, lazy loading might not give you enough data, and you either get Lazy Loading Exceptions, or you have multiple trips back and forth to the database to get what you need.

Here's a little tutorial on how hibernate works. It might provide you some more information on what you're after:

How Hibernate Works

-Cameron McKenzie
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO Actually If the association is large then It will create any problem??.Actually I had a discussion,in that ,people suggest eager and lazy fetching has many advantage as well disadvantage.

I can figure out advantage but not able to find Disadvantage since I do not work on extensively

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually Cameron gave you the entire gist of it for you to see the advantages and disadvantages.

Basically they have the same advantages and disadvantages but opposite of each other.

Fetching should be use case driven and not mapping driven. So for me the best approach is everything is mapped as lazy loading, and now I can set the fetching strategy at query time. So when I have a use case that needs X amount of data I get X amount of data and nothing more and nothing less. If you choose lazy all the time for everything then you will be getting less than X for most of your use cases. If you eager fetch everything by default, then you will be getting more than X for most of your use cases.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic