Spring配置C3P0与Hibernate?
我有一个 Spring/JPA 应用程序,其中 Hibernate 作为 JPA 提供者。我通过以下方式在 Spring 中配置了 C3P0 数据源:
<bean id="myJdbcDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- Connection properties -->
<property name="driverClass" value="$DS{database.class}" />
<property name="jdbcUrl" value="$DS{database.url}" />
<property name="user" value="$DS{database.username}" />
<property name="password" value="$DS{database.password}" />
<!-- Pool properties -->
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
然后,我在 Spring 实体管理器工厂中指定了该数据源,如下所示:
<bean id="myLocalEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myapp-core" />
<property name="dataSource" ref="myJdbcDataSource" />
</bean>
但是,我最近在浏览 Maven 工件时注意到“hibernate-c3p0”。这是什么?这是我需要使用的东西吗?或者我已经正确配置了这个?
I have a Spring/JPA application with Hibernate as the JPA provider. I've configured a C3P0 data source in Spring via:
<bean id="myJdbcDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- Connection properties -->
<property name="driverClass" value="$DS{database.class}" />
<property name="jdbcUrl" value="$DS{database.url}" />
<property name="user" value="$DS{database.username}" />
<property name="password" value="$DS{database.password}" />
<!-- Pool properties -->
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
I then specified this data source in the Spring entity manager factory as follows:
<bean id="myLocalEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myapp-core" />
<property name="dataSource" ref="myJdbcDataSource" />
</bean>
However, I recently noticed while browsing maven artifacts a "hibernate-c3p0". What is this? Is this something I need to use? Or do I already have this configured properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
hibernate-c3p0.jar 提供了类 org.hibernate.connection.C3P0ConnectionProvider ,它是 Hibernate ConnectionProvider 合约的基于 C3P0 的实现。当您想要使用 C3P0 作为 Hibernate 的独立连接池(通过 hibernate.cfg.xml 文件配置)时,您需要此工件。由于您使用的是 Spring,因此不需要它。
The hibernate-c3p0.jar provides the class
org.hibernate.connection.C3P0ConnectionProvider
, a C3P0-based implementation of the HibernateConnectionProvider
contract. You need this artifact when you want to use C3P0 as Hibernate's standalone connection pool (that you configure through thehibernate.cfg.xml
file). Since you're using Spring, you don't need it.org.hibernate:hibernate-c3p0 看起来就像您将 Hibernate 配置为直接使用 C3P0 时将使用的模块。
假设您发布的配置适合您,您不应该需要它 - 是吗?
org.hibernate:hibernate-c3p0 looks like the module you would use if you were configuring Hibernate to use C3P0 directly.
You shouldn't need it assuming the configuration you posted works for you - does it?