Spring配置C3P0与Hibernate?

发布于 2024-09-05 01:18:52 字数 1245 浏览 12 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-09-12 01:18:52

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 Hibernate ConnectionProvider contract. You need this artifact when you want to use C3P0 as Hibernate's standalone connection pool (that you configure through the hibernate.cfg.xml file). Since you're using Spring, you don't need it.

淡水深流 2024-09-12 01:18:52

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文