Develop API for load-by-multiple-ids

Description

Hibernate does not have any explicit handling for excessive expressions in an in-list expression in HQL. There are many reported issues that come out of this (see linked issues, and their linked issues). In my opinion, the vast majority of these come from (imo) invalid queries.

However, there is one use case where this complaint comes up that is valid imo; specifically the case of wanting to load multiple entities by id at one shot. We should develop an API for allowing this. Something along the lines of:

IdentifierLoadAccess.java

1 2 3 4 5 public interface IdentifierLoadAccess<T> { ... <K extends Serializable> List<T> multiLoad(K... ids); <K extends Serializable> List<T> multiLoad(List<K> ids); }

In support of that (and batch fetch loading too), consider adding a "optimal batch size" determination strategy. Today we rely on the user explicitly telling us the batch size to use. Would be nice to have a determination for that as a default, especially a Dialect-specific determination:

BatchLoadSizingStrategy.java

1 2 3 public interface BatchLoadSizingStrategy { int determineOptimalBatchLoadSize(int numberOfKeyColumns, int numberOfKeys); }

Dialect.java

1 2 3 4 5 6 public class Dialect { ... public BatchLoadSizingStrategy getDefaultBatchLoadSizingStrategy() { ... } }

Also allow users to specify a custom BatchLoadSizingStrategy; the Dialect one is just the default.

Would also be nice to allow batch fetch loading to leverage this strategy-based determination. One option would be to simply make the size on @BatchSize optional. That unfortunately leaves @BatchSize poorly named overall. Maybe deprecating @BatchSize in favor of a new @BatchLoadable with an optional size attribute is better?

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Steve Ebersole

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Major