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.
|