[hibernate-dev] MultiCollectionOwnerIdentifierLoadAccess?
Steve Ebersole
steve at hibernate.org
Mon Jan 16 10:06:31 EST 2017
Sanne,
yes and no. It depends on your fetch strategy for that collection. To
review you have:
1. SELECT (eager or lazy)
2. JOIN (eager)
3. BATCH (lazy)
4. SUBSELECT (lazy)
To illustrate let's consider a familiar collection role: Order#lineItems.
I'll only consider LAZY scenarios, since eager would make no sense here...
SUBSELECT comes closest to what you describe. That loads *all* collections
of a given role that are attached to the Session, although it has no idea
about which are initialized and which are not. If you have associated 50
Order entities with the Session, accessing one collection forces loading of
all of them. But it queries for the collection elements for all 50,
regardless of whether one or more were already initialized.
BATCH is similar but limits the collections initialized to a certain number
which it then queries for by FK. This approach does actually consider
which collections have already been initialized and excludes them from the
db query.
SELECT is typical n+1. The collections are initialized one by one as they
are accessed.
What I propose is different from all of these, but BATCH comes closest
(just like we saw with entity multi-id loading). The idea is to allow the
application to control the batches. It would look something like:
session.byMultipleCollectionKeys( "com.acme.Order.lineItems" ).initialize(
1, 2, 3, 4 );
I am not a fan of the `byMultipleCollectionKeys` name. Also, should this
be based on the collection key (the FK) or the collection's owner id?
Probably the latter makes more sense.
But the general idea is that the application knows which collections are
needed next and can initialize just those. The method has no return as it
works on the collections associated with the Session.
On Mon, Jan 16, 2017 at 3:58 AM Sanne Grinovero <sanne at hibernate.org> wrote:
> It sounds interesting but I'm not sure I understand you. Could you
> elaborate please? Isn't this the same "thing" which I'd trigger when
> attempting to access a member of a non-initialized & attached
> collection?
>
> Thanks,
> Sanne
>
>
> On 14 January 2017 at 20:21, Steve Ebersole <steve at hibernate.org> wrote:
> > I'm curious if anyone sees value in
> > a MultiCollectionOwnerIdentifierLoadAccess variant (or some more concise
> > name) of MultiIdentifierLoadAccess for bulk initializing a collection
> role
> > based on their owner ids?
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
More information about the hibernate-dev
mailing list