Hibernate c3p0配置没有任何影响

时间:2015-02-16 18:54:12

标签: java hibernate c3p0

我正在尝试将c3p0连接池添加到现有的hibernate配置中。 但它没有任何影响,而且hibernate仍然使用默认池。 单独的Hibernate配置工作正常,所以我绝对肯定没有问题。

想知道这里是否有人可以指出我的错误或建议我如何调试问题?

我不使用Spring框架。

<hibernate-configuration>
<session-factory>

<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
    <property name="hibernate.connection.password">passwd</property>
    <property name="hibernate.connection.url">jdbc:db2://server:port/database</property>
    <property name="hibernate.connection.username">username</property>

    <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="hibernate.connection.autocommit">false</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.default_schema">DB Schema</property>
    <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
    <property name="hibernate.format_sql">false</property>
    <property name="hibernate.max_fetch_depth">4</property>
    <property name="hibernate.search.autoregister_listeners">false</property>
    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.connection.isolation">1</property>
    <property name="hibernate.jdbc.batch_size">50</property>

<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">900</property>

<mapping resource="table.hbm.xml" />

</session-factory>
</hibernate-configuration>

以下是我的罐子:

hibernate3.jar
hibernate-c3p0-3.5.0-Final.jar

日志中的陈述:

hibernate.cfg.Environment - Hibernate 3.5.0-Final
INFO  ManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO  ManagerConnectionProvider - Hibernate connection pool size: 20

1 个答案:

答案 0 :(得分:3)

尝试从c3p0配置连接提供程序类。

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

此外,最好添加hibernate配置doctype,这有助于查找任何拼写错误。

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<强>更新 您需要在类路径中包含mchange库。这个link可能会对您有所帮助。

相关问题