此内容没有您所选择的语言版本。

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:
Expand
Table 2.7. Configuration Properties for the C3p0 Connection Pool
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:
Expand
Table 2.8. JNDI Properties
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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat