Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lazy association

 
Saumya Nair
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me understand what is meant by Lazy fetchin ???
N how is it helpful ??? In what cases should it be set to true/false/proxy
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sowmya,
I dont know in what context are you asking? Also have you posted the query in the appropriate forum?
But according to my knowledge, Lazy Loading/Fetching is the process of loading the resources on demand irrespective of the type/nature of resources.
It depends on the Application Server as well the configuration of the user. You can very well say the App Server to load the resources when it starts. Say for example, in terms of Servlets, you got a tag named <load-on-startup> whose value intimates the level of loading that particular servlet. It should be greater than zero to load the servlet when the application server gets started.
I believe the concept (similar to "just in time" or "on demand") will hold good for other contexts too (if you have asked for some other context).

Hope it helps out.
Good times ahead,
Raghavan alias Saravanan M.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the typo in my prev post.

It depends on the Application Server as well the configuration of the files by the user (say web.xml for a web application etc).
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm - Raghavan alias Saravanan Muthu, I think you've missunderstood what Saumya Nair is asking. The question I believe is about the concept of lazy initialization in Hibernate (please correct me if I am wrong Saumya Nair, since you don't mention which ORM you are asking about).

If it is, then this is a technique whereby Hibernate can bring data from the database into its Session only when it is asked for. Consider two tables, one called Person, the other called Address, and a Person has an Address. Suppose you map these in Hibernate to use laze initialization. If you get a Person on its own, will bring back a "proxy" object for the associated Address. In reality, this is little more than the ID of the Address, plus proxy methods. But what it does mean is you can access the associated Address in code without the fear of it being null and Hibernate will go back to the database and populate the Address for you.

When should you use this? Probably all the time. That is unless you have data in two related tables which you know will almost always be accesses together. Suppose you know you'll always need the Address when you get the Person then I wouldn't map this association lazily.

Does this make any sense?
[ April 25, 2006: Message edited by: Paul Sturrock ]
 
Saumya Nair
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,Paul you are right.I was asking about lazy fetching in Hibernate.My mistake i dint mention it... Thanks for the info.It did help..


Would like to know about Optimistic/Pesimistic locking too...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help.


Would like to know about Optimistic/Pesimistic locking too...

Then I suggest you start a new topic and ask your question, perhaps with a little more detail? People here are only too glad to help.
 
Saumya Nair
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank u once again..

Posted it as a new topic
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. thats fine Paul. Thats why i have started in my post with "i dont know in what context you are asking".

Anyways, i prefer the common and general interpretation for the "lazy loading/fetching" term is "loading on demaind" rite?

Thanks,
Raghavan alias Saravanan M.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic