-->
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: Most efficient way to lookup list entry in 1:many relation
PostPosted: Tue Jul 20, 2010 8:52 am 
Newbie

Joined: Wed Jun 30, 2010 4:20 am
Posts: 3
I have an entity (EntityA) that contains a list of other entities (EntityB) - it is a 1:n relationship using an association table with a sequence field to record the order. Both entities have a compound key. The association is lazily loaded. Given that I have the key of the EntityB that I want to retrieve from the list contained within EntityA:

- is there a way to just load the entity I want, rather than iterating through the list and trying to match the key on a iterative basis?

- rather than unnecessarily hydrating objects I don't need, is there way I can look through the association table to get the sequence number of the list entry (matching on my known key), and then call getXYZList().get(sequence), without having to do my own plumbing? The key structure is constant throughout a large number of entities within the application and would lend itself to static sql, but obviously the name of the association table changes per relation, and I don't want to hardcode it.

- when getXYZList() is called, is each entry in the list hydrated anyway, making any effort at optimisation like that outlined in my previous query redundant?

My goal is to make the lookups as efficient as possible and avoid filling the cache with unnecessary entities.

Many thanks,
Jim.


Top
 Profile  
 
 Post subject: Re: Most efficient way to lookup list entry in 1:many relation
PostPosted: Thu Jul 29, 2010 3:30 pm 
Newbie

Joined: Tue Oct 19, 2004 4:05 am
Posts: 14
Location: ireland
i don't think it's possible to get what you want here. the way collections are implemented in hibernate is that one gets everything or nothing. there is a batch-size parameter you could use in order to limit the number of objects being loaded from a database but that would be all i can think of.


Top
 Profile  
 
 Post subject: Re: Most efficient way to lookup list entry in 1:many relation
PostPosted: Fri Jul 30, 2010 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you can map it using Map type collections, and then play with options like the fetch options and/or @ExtraLazy (don't remember the details, but there are plenty of examples on the net)

_________________
Sanne
http://in.relation.to/


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.