Skip to content

Commit d3a93dd

Browse files
committed
big improvements to docs surrounding ConnectionProvider
1 parent 9dcae54 commit d3a93dd

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

documentation/src/main/asciidoc/introduction/Tuning.adoc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ The connection pool built in to Hibernate is suitable for testing, but isn't int
3636
Instead, Hibernate supports several different connection pools, including our favorite, Agroal.
3737

3838
Hibernate will automatically make use of `AgroalConnectionProvider` if the module `org.hibernate.orm:hibernate-agroal` is available at runtime.
39+
So just add it as a runtime dependency, and you're all set.
40+
41+
Well, actually, that's a bit fragile, since Hibernate silently falls back to using the default connection pool if Agroal happens to be missing at runtime.
42+
Perhaps it's better to set this configuration property:
43+
44+
[%breakable,cols="37,~"]
45+
|===
46+
| Configuration property name | Purpose
47+
48+
| link:{doc-javadoc-url}/org/hibernate/cfg/JdbcSettings.html#CONNECTION_PROVIDER[`hibernate.connection.provider_class`] | Explicitly specify a link:{doc-javadoc-url}/org/hibernate/engine/jdbc/connections/spi/ConnectionProvider.html[connection pool], for example, `agroal`, `hikaricp`, `c3p0`, or `oracleucp`.
49+
|===
50+
51+
TIP: You can set `hibernate.connection.provider_class` to `agroal` so that Hibernate fails at startup if Agroal is missing.
52+
3953

4054
To properly configure Agroal, you'll need to set some extra configuration properties, in addition to the settings we already saw in <<basic-configuration-settings>>.
4155
Properties with the prefix `hibernate.agroal` are passed through to Agroal:
@@ -100,9 +114,11 @@ All we need to do is set a single property:
100114
|===
101115
| Configuration property name | Purpose | Alternative
102116

103-
| `hibernate.jdbc.batch_size` | Maximum batch size for SQL statement batching | `setJdbcBatchSize()`
117+
| link:{doc-javadoc-url}/org/hibernate/cfg/BatchSettings.html#STATEMENT_BATCH_SIZE[`hibernate.jdbc.batch_size`] | Maximum batch size for SQL statement batching | `setJdbcBatchSize()`
104118
|===
105119

120+
That said, batching is rarely the most convenient or most efficient way to update or delete many rows at once.
121+
106122
[TIP]
107123
====
108124
Even better than DML statement batching is the use of HQL `update` or `delete` queries, or even native SQL that calls a stored procedure!

hibernate-core/src/main/java/org/hibernate/cfg/CacheSettings.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import org.hibernate.Incubating;
88
import org.hibernate.annotations.CacheLayout;
9-
import org.hibernate.cache.internal.NoCachingRegionFactory;
109
import org.hibernate.cache.spi.RegionFactory;
1110
import org.hibernate.cache.spi.TimestampsCacheFactory;
1211
import org.hibernate.jpa.SpecHints;
@@ -111,14 +110,21 @@ public interface CacheSettings {
111110
/**
112111
* The {@link RegionFactory} implementation, either:
113112
* <ul>
114-
* <li>an instance of {@link RegionFactory},
115-
* <li>a {@link Class} implementing {@link RegionFactory}, or
116-
* <li>the name of a class implementing {@link RegionFactory}.
113+
* <li>a short strategy name, for example, {@code jcache} or
114+
* {@code infinispan},
115+
* <li>an instance of {@code RegionFactory},
116+
* <li>a {@link Class} object representing a class that implements
117+
* {@code RegionFactory}, or
118+
* <li>the name of a class implementing {@code RegionFactory}.
117119
* </ul>
118-
* <p>
119-
* Defaults to {@link NoCachingRegionFactory}, so that caching is disabled.
120+
*
121+
* @settingDefault {@link org.hibernate.cache.internal.NoCachingRegionFactory},
122+
* so that caching is disabled.
120123
*
121124
* @see #USE_SECOND_LEVEL_CACHE
125+
*
126+
* @apiNote The term {@code "class"} appears in the setting name due to legacy reasons;
127+
* however it can accept instances.
122128
*/
123129
String CACHE_REGION_FACTORY = "hibernate.cache.region.factory_class";
124130

hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,28 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
234234
* Specifies a {@link ConnectionProvider} to use for obtaining JDBC connections,
235235
* either:
236236
* <ul>
237+
* <li>a short strategy name like {@code agroal}, {@code hikaricp},
238+
* {@code c3p0}, or {@code ucp},
237239
* <li>an instance of {@code ConnectionProvider},
238-
* <li>a {@link Class} representing a class that implements
240+
* <li>a {@link Class} object representing a class that implements
239241
* {@code ConnectionProvider}, or
240242
* <li>the name of a class that implements {@code ConnectionProvider}.
241243
* </ul>
244+
* <p>
245+
* If this property is not explicitly set, a connection provider is chosen
246+
* automatically:
247+
* <ul>
248+
* <li>if {@link #JAKARTA_JTA_DATASOURCE} or {@link #JAKARTA_NON_JTA_DATASOURCE}
249+
* is set, {@linkplain org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl
250+
* a datasource-based implementation} is used;
251+
* <li>otherwise, a {@code ConnectionProvider} is loaded automatically as a
252+
* {@linkplain java.util.ServiceLoader Java service};
253+
* <li>but if no service is found, or if more than one service is available,
254+
* {@linkplain org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
255+
* a default implementation} is used as a fallback.
256+
* </ul>
257+
* <p>
258+
* The default implementation is not recommended for use in production.
242259
*
243260
* @apiNote The term {@code "class"} appears in the setting name due to legacy reasons;
244261
* however it can accept instances.

hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/ConnectionProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.engine.jdbc.connections.spi;
6+
67
import java.sql.Connection;
78
import java.sql.SQLException;
89

0 commit comments

Comments
 (0)