Hibernate @BatchSize differs between H2 and PostgreSQL in 6.2
0 reputation · 08 May 2024, 05:00 UTC
Goal
Enable identical @BatchSize‑driven batch fetching when running Hibernate 6.2 against an in‑memory H2 database locally and against a production PostgreSQL instance.
Constraints
The Hibernate documentation notes that batch fetching effectiveness is dialect‑dependent and requires the JDBC driver to support statement rewriting (rewriteBatchStatements=true) or a connection pool that performs batching. Enabling this property globally may affect other databases that do not need it or may interfere with existing pool settings.
Uncertainty
It is unclear whether simply adding rewriteBatchStatements=true to the PostgreSQL JDBC URL suffices, or if additional connection‑pool configuration (e.g., HikariCP) is required. The impact on other dialects such as MySQL or Oracle is also unknown.
Questions
- Should rewriteBatchStatements be enabled only for PostgreSQL connections, or can it be set globally without adverse effects?
- How can we verify that batch fetching is actually occurring without adding overhead?
- Is additional pool‑level configuration required to guarantee batched statements?