Hibernate / Spring Framework中的TestConnectionOnCheckin c3p0配置属性

时间:2010-06-16 17:55:53

标签: hibernate spring c3p0 entitymanager

我想为c3p0设置testConnectionOnCheckin属性。

但是我无法这样做,因为c3p0数据源是在hibernate entity-manager bean中代表我创建的。

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
<property name="jpaProperties">
  <props>
    <prop key="hibernate.dialect">${taxeng.entityManagerFactory.dialect}</prop>
    <prop key="hibernate.hbm2ddl.auto">${taxeng.entityManagerFactory.ddl}</prop>
    <prop key="hibernate.cache.provider_class">${taxeng.entityManagerFactory.cache}</prop>
    <!-- Note that we use this due to the "ClassNotFoundException: org.hibernate.hql.ast.HqlToken" issue -->
    <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>

    <!-- Database connection pooling -->
    <prop key="hibernate.c3p0.min_size">${taxeng.hibernate.c3p0.min_size}</prop>
    <prop key="hibernate.c3p0.max_size">${taxeng.hibernate.c3p0.max_size}</prop>
    <prop key="hibernate.c3p0.timeout">${taxeng.hibernate.c3p0.timeout}</prop>
    <prop key="hibernate.c3p0.acquire_increment">${taxeng.hibernate.c3p0.acquire_increment}</prop>
    <prop key="hibernate.c3p0.idle_test_period">${taxeng.hibernate.c3p0.idle_test_period}</prop>
    <prop key="hibernate.c3p0.max_statements">${taxeng.hibernate.c3p0.max_statements}</prop>
    <prop key="hibernate.show_sql">false</prop>
  </props>
</property>

每个<prop key...1&gt;是一个hibernate配置键,hibernate用它代表我创建一个c3p0数据源。

但是,我找不到hibernate配置键,它将设置c3p0数据源的testConnectionsOnCheckin属性。

有钥匙吗?如果没有,那么我应该直接设置entityManagers数据源吗?在这之前我应该​​知道任何技巧吗?

注意:testConnectionsOnCheckout不是一个可行的选项,它有一个相应的hibernate配置密钥。

1 个答案:

答案 0 :(得分:1)

只有一部分c3p0属性可以被覆盖:

http://www.mchange.com/projects/c3p0/index.html#hibernate-specific

对于其他人(包括testConnectionsOnCheckin)需要在c3p0.properties中重写