C3P0与Hibernate的春季配置? [英] Spring configuration of C3P0 with Hibernate?

查看:110
本文介绍了C3P0与Hibernate的春季配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Hibernate作为JPA提供者的Spring / JPA应用程序。我已经在Spring中配置了一个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" />

然后指定这个数据源在Spring实体管理器工厂中,如下所示:

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>

然而,我最近在浏览maven工件时注意到了一个hibernate-c3p0。这是什么?这是我需要使用的东西吗?或者我已经配置正确?

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?

推荐答案

hibernate-c3p0.jar提供类 org .hibernate.connection.C3P0ConnectionProvider ,一个基于C3P0的Hibernate ConnectionProvider 合同的实现。当您希望将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.

这篇关于C3P0与Hibernate的春季配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆