Need for a new -to-many fetch mode, retrieving children ids only (otherwise L2 cache is poorly used when retrieving collections of cached objects)

Description

The proposed improvement is a -to-many association fetch mode (maybe lazy mode) where only children ids would be fetched when we fetch the collection, rather than whole children entities, as it is the case now.

Suppose we use a second level cache for children entities, and that we warm this cache up at application start : We will still fetch these children entites each time we fetch a collection of such entities, althought all of them were available in the second level cache !
Of course using a collections cache helps a bit, but only a bit, because of course we will then fetch a given collection only once, but that could still mean a lot of unnecessary entity fetching if one entity is in many collections.

With the new fetch mode proposed, we would only fetch the children ids list, and then get the entities one by one lazily, allowing for using the cache, so the only SQL generated would for example be if we are fetching Bids for an Item :
SELECT bids.id FROM bids WHERE bids.item_id = 123
instead of
SELECT bids.id, bids.user, bids.date, ... FROM bids WHERE bids.item_id = 123

If the collection itself is cached, the result can be cached as the collection value (L2 collections cache only contains collections of ids, if I'm not mistaking...?)
The mode could then also be used warm collections caches up.

Maybe there is a way to get around this, but I found neither that was satisfactory.
The "best" I found is to link the father entity to a collection of "id entities", themselves linked (one-to-one) to the "real", big entity. But this is not handy.

Environment

hibernate : 3.3.0
database : probably not pertinent (sybase 12.5)

Assignee

Unassigned

Reporter

Yannick le Restif

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure