-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Lazy loading
PostPosted: Tue Jan 31, 2006 1:08 pm 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I want to know that when an object is loaded if it is defined lazy = "true",

whenever it is used?

or whenever its getter method is called?

or else?



<class name="Cat" table="cats" lazy = "true">

.....
.....

<bag name="matcheds" lazy = "true" table = "MATCHEDS"
cascade="all">
<key column="CAT_ID">
<many-to-many class="Cat"
column="MATCHED_CAT_ID">
<bag>

...


public void addMatchCat(Cat c) {
if (matcheds.contains(c)) {
return;
}
else kittens.add(c);
}

In that example, when I debugged, I saw that already Cat c is in matcheds list, contains method returns false. How can this happen?

When I set lazy = "false" to the class, everything is fine (properly working but too more queries)

_________________
-developer


Top
 Profile  
 
 Post subject: Am I correct??
PostPosted: Tue Jan 31, 2006 1:28 pm 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
Aha,

equals check doesnt force to load the lazy object.

Am I correct??

If object x is lazy loaded than calling


calling y.equals(x) doesnt load the object X,

but calling x.getName() loads the lazy object full.

Am I correct??

_________________
-developer


Top
 Profile  
 
 Post subject: Re: Am I correct??
PostPosted: Tue Jan 31, 2006 2:11 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
borak wrote:
calling y.equals(x) doesnt load the object X,

but calling x.getName() loads the lazy object full.

Am I correct??

Thats correct. Only calling a method on the lazily loaded object will cause it to be loaded from the database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.