@caristu The best way to control the amount of data you fetch is at query-time because the fetch strategy is given by the current business user requirements.
Default batch fetching strategy or mapping-time constructs like
@LazyCollection are like applying a band-aid on a broken foot. They don’t really fix the actual problem, they only bring some relief in the short-run.
If performance is important to you, you want to:
- switch to LAZY fetching for all association types,
- use entities only if you want to later modify them and benefit from optimistic locking or optimistic locking
- use DTOs for read-only projections (e.g. trees, tables, reports)
- avoid anti-patterns like Open-Session in View or
If you do that, you will see that there is no need for stuff like
@BatchSize, and, not only that you’ll get better memory utilization on the JVM size, but you avoid lots of processing on the DB side as well (CPU, memory, IO) as well on the networking layer.