-->
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.  [ 4 posts ] 
Author Message
 Post subject: Lazy load collections with Id's only
PostPosted: Thu Sep 09, 2010 10:01 pm 
Newbie

Joined: Thu Sep 09, 2010 9:56 pm
Posts: 2
Is it possible to lazy load collections with Id's only?

for e.g. I have one-to-many relation between Customer -> Orders. When I load Customer object (session.get), I iterate over the Orders but I only use "Id" field of the Order. Instead of loading entire collection of Order with all the fields, is it possible to load only "id" field and if I use any other field, rest of the fields will be populated?

Thanks.


Top
 Profile  
 
 Post subject: Re: Lazy load collections with Id's only
PostPosted: Thu Sep 09, 2010 11:56 pm 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Yes it is possible !! If you are using the HQL navigate the reference object to identifier.

Say a Person has n number of Address. Here Person -< Address (1-many)

now List<Long> addressIds = session.createQuery("sample","select add.id from Person p,
Address A where a.person_id=p.id").list();

Hope this resolves your problem!!

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Lazy load collections with Id's only
PostPosted: Fri Sep 10, 2010 1:51 am 
Newbie

Joined: Thu Sep 09, 2010 9:56 pm
Posts: 2
shynate26 wrote:
Yes it is possible !! If you are using the HQL navigate the reference object to identifier.

Say a Person has n number of Address. Here Person -< Address (1-many)

now List<Long> addressIds = session.createQuery("sample","select add.id from Person p,
Address A where a.person_id=p.id").list();

Hope this resolves your problem!!


Not exactly. What I meant was I don't want to create a special query. Here's a sample code:

Session s = SessionFactory.openSession();
Person p = s.get(1234);
for (Address a : p.getAddresses()) {
print(a.getId()); // normally, all addresses related to the person will be fetched here and loaded into the collection.
// I want to only load the Id's at this point and minimize the amount of data that is transferred from DB to application.

print(a.getStreetName()); // This is where I would like to load the entire address collection or this address object.
}


Top
 Profile  
 
 Post subject: Re: Lazy load collections with Id's only
PostPosted: Tue Sep 14, 2010 8:42 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
http://docs.jboss.org/hibernate/core/3. ... properties

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


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