-->
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.  [ 5 posts ] 
Author Message
 Post subject: Pulling one instance from a large lazy collection
PostPosted: Mon Apr 30, 2007 10:40 pm 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
I have an object that has a collection which can contain many objects (let's say 30,000 or so). I need the ability to pull one instance by id from the collection for display on the UI. I'd originally thought that using filtered collections might be the way to get that done but Hibernate filters are a bit more course-grained than that.

The contained collection is already lazily loaded which, as I understand it, already creates proxies that contain the ids. Would the normal Hibernate idiom be to find the instance by id from the proxies and simply call another method on the found instance to get Hibernate to load the instance information from the database? If that isn't the way to do it, am I simply missing the "correct" way to do it?

thanks a ton,
phayte


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 5:03 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Why can't you just write a specific query to retrieve your object? This way you wouldn't risk loading more objects than you need?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 8:31 am 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
Since I already had a reference to the parent containing object I was hoping there would be a way to walk the object references to get the instance that I needed as opposed to making another call from a DAO.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 12:02 pm 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
I was wondering if I mapped the collection as "extra-lazy" and simply looked for the child instance by id if that would get me to where I need. If I iterate over the extra-lazy collection and simply ask for the identifier will that cause the instance's information to be loaded or are they only loaded when you ask for something other than the identifier?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 12:23 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
In fact, Hibernate is smart enough to not trigger the select when only requesting the getter corresponding to the mapped it. Obviously take care of never calling another getter/setter inside the "id" one, as it would trigger the corresponding select.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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