-->
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.  [ 2 posts ] 
Author Message
 Post subject: Clarificatin in Lazy loading..
PostPosted: Mon Oct 06, 2008 4:37 am 
Newbie

Joined: Wed Oct 01, 2008 4:44 am
Posts: 3
Hi ,

I have a confusion about the objects lazy loading in the collection.

This is the scenario:

Class A {
Set<B> bees = new HashSet<B>();
setBees() {}
getBees() {}
}
Class B {
String name;
setName(String name) {this.name = name;}
getName() {return name;}
}

A.hbm.xml:
<set name = “bees” lazy = “true” order-by=”name” >
….
</set>

Here I don’t want to load all the B objects when I load the Object of A class. So I have given “lazy=”true” in the mapping file.

I need to execute only two methods on the collections: size() and the getName() method on the first object.

I have a confusion here that whether hibernate loads all the objects when I call the size() method on collection?
And
Does hibernate loads only one object when I call the getName() method on the first object like getBees().get(0).getName(); or all the objects?

My requirement is that I don’t want to load all the objects except first object.

Please kindly clarify me?

Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 7:36 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
In the simplest case the answer to your question is that Hibernate will load all objects and populate the set when you call a method on it.

There is also the possibility to map the set with lazy="extra". I have no experience of this setting and don't really know what it does, and I can only find one sentence about it in the Hibernate documentation: http://www.hibernate.org/hib_docs/v3/re ... pping.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.