Hibernate version:
3.0.5
I know that you can configure your mapping files with eager fetching, subselect fetching, batching, etc., and you can also use join fetching in HQL queries or equivalent in the Criteria API, but is there any way to prefetch relationships on a specific set of objects without refetching the source objects, or modifying the mappings? What I am aiming at is a utility that can be used from my application layer to generically specify to my data access layer what will be needed in a particular display.
For example, (using CaveatEmptor model)
Lets say I'm building a web application and one of the pages gets setup with a set of Items and displays them. Lets say that this particular display (however inefficient) needs to show for each item:
bids.user.*, bids.user.address.* (* meaning all non association properties)
I'd like to have something like the following implemented in the data access layer:
prefetcher.prefetchKeyPaths(items, new String[] {"bids.user", "bids.user.address"})
that can then be used to direct the data access to do whatever it can to fetch those relationships as efficiently as possible so they may be used in a display, without persistence layer code leaking into the application layer.
I'm actually coming from Apple's EOF, where I was able to build such a utility over what would translate in Hibernate to something like Hibernate.initialize(Object persistentObject) and Hibernate.initialize(Collection sourceObjects, String associationName). The first exists, but the second does not.
If anyone has any suggestions on how to accomplish this, that would be great. My implementation from EOF would actually port right over if I just had some way of batch intializing an association on a set of source objects(Hibernate.initialize(Collection sourceObjects, String associationName)
Thanks in advance,
-lenny
|