aspose file tools*
The moose likes Object Relational Mapping and the fly likes Lazy association Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Lazy association" Watch "Lazy association" New topic
Author

Lazy association

Saumya Nair
Ranch Hand

Joined: Apr 25, 2006
Posts: 34
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

Joined: Apr 20, 2006
Posts: 3344

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.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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

Joined: Apr 14, 2004
Posts: 10336

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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Saumya Nair
Ranch Hand

Joined: Apr 25, 2006
Posts: 34
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Apr 25, 2006
Posts: 34
thank u once again..

Posted it as a new topic
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lazy association
 
Similar Threads
What is lazy initialization.
General
WA #1.....word association
Another 'Y' game
lazy loading