此内容没有您所选择的语言版本。
2.3. Connection Pooling
2.3.1. About Connection Pooling 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Hibernate includes a rudimentary internal connection pooling algorithm for development and testing purposes. Use a third party pool for improved performance and stability.
To set a third party connection pool, replace the
hibernate.connection.pool_size property with the appropriate settings for your selected connection pool. Setting a new value automatically disabled Hibernate's internal connection pool.
2.3.2. C3P0 Connection Pool 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
C3P0 is an open source JDBC connection pool that is distributed with Hibernate. C3P0 is available in the
lib/ directory. Hibernate uses org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider for connection pooling if the hibernate.c3p0 connection properties are set.
The following table contains
hibernate.c3p0 connection properties to set to use the c3p0 connection pool in Hibernate:
| Property | Details |
|---|---|
hibernate.c3p0.min_size | The minimum number of concurrent connections per connection identity. |
hibernate.c3p0.max_size | The maximum number of concurrent connections per connection identity. |
hibernate.c3p0.timeout | The period an idle connection is allowed to remain in the connection pool before it is closed and removed from the pool. |
hibernate.c3p0.max_statements | The maximum size of the statement cache. |
2.3.3. Use JNDI to Obtain a Connection 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To use Hibernate inside an application server, configure Hibernate to obtain connections from an application server (
javax.sql.Datasource) that is registered in JNDI. Set more than one of the following properties to configure JNDI to obtain a connection:
| Property Name | Description |
|---|---|
hibernate.connection.datasource | Datasource JNDI name (mandatory). |
hibernate.jndi.url | URL of the JNDI provider (optional). |
hibernate.jndi.class | Class of the JNDI InitialContextFactory (optional). |
hibernate.connection.username | Database user (optional). |
hibernate.connection.password | Database user's password (optional). |
2.3.4. Other Connection Specific Configurations 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Pass custom connection properties by appending the name of the new property to
hibernate.connection. For example, to specify a charSet property, specify a new charSet connection property names hibernate.connection.charSet.
Pass custom plugin strategies to obtain JDBC connections by implementing the
org.hibernate.service.jdbc.connections.spi.ConnectionProvider and by specifying a custom implementation with the hibernate.connection.provider_class property.