• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fetching.lazy

 
Vinoth kumar Gajapathy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new to hibernate can any one tell me why we using fetching.lazy in database coding side(on onetomany,etc) and what is purpose of this and is any other type ? explain please
 
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
There is both eager and lazy fetching.

Basically, an object can be associated with many other objects. At runtime, you may not need to know about all of the associated objects. Say you have a User with ten addresses. If you want to know the user's name, should you do all the database calls to get the 10 addresses as well? Definitely NOT. So, we make associations lazy, and as such, associated classes do not get populated with real data until that real data is needed. It's very efficient, and often very preferrable. I also believe it is the default with all but one-to-one associations.

-Cameron McKenzie
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic