Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java C3P0配置!在哪里,如何?_Java_Hibernate_Jpa 2.0_Connection Pooling_C3p0 - Fatal编程技术网

Java C3P0配置!在哪里,如何?

Java C3P0配置!在哪里,如何?,java,hibernate,jpa-2.0,connection-pooling,c3p0,Java,Hibernate,Jpa 2.0,Connection Pooling,C3p0,我们正在使用JPA2.0和Hibernate3.0实现一个Web应用程序。连接池配置在META-INF文件夹中的persistence.xml中设置 persistence.xml: <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="MyPU" transaction-type="RESOURCE_LOCAL">

我们正在使用JPA2.0和Hibernate3.0实现一个Web应用程序。连接池配置在META-INF文件夹中的persistence.xml中设置


persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="MyPU" transaction-type="RESOURCE_LOCAL">
        <!-- Entity Classes-->
        <properties>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="bytecode.provider"   value="org.hibernate.bytecode.javassist.BytecodeProviderImpl"/>
            <property name="hibernate.connection.username" value="{username}"/>
            <property name="hibernate.connection.password" value="{password}"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.connection.url" value="{jdbc url}"/>

            <property name="hibernate.c3p0.min_size" value="1"/>
            <property name="hibernate.c3p0.timeout" value="1000"/>
            <property name="hibernate.c3p0.acquire_increment" value="1"/>
            <property name="hibernate.c3p0.idle_test_periods" value="600"/>
            <property name="hibernate.c3p0.testConnectionOnCheckin" value="true"/>
            <property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1;"/>
       </properties>
    </persistence-unit>
</persistence>


连接池配置有问题。配置似乎没有效果,8小时后连接将断开。
我们是否需要另一个配置文件,如hibernate.cfg.xml或hibernate.properties?

好问题,坏标题:)我想我在你的回复中回答了这个问题:

我在persistence.xml中使用的方法也有同样的问题。xml对c3p0没有影响

我尝试将一个名为
c3p0config.xml
的xml文件放入
WEB-INF/classes
中,它工作得非常好

以下是
c3p0 config.xml
文件的示例:

<c3p0-config>
  <default-config>
    <property name="automaticTestTable">con_test</property>
    <property name="checkoutTimeout">30000</property>
    <property name="idleConnectionTestPeriod">30</property>
    <property name="initialPoolSize">10</property>
    <property name="maxIdleTime">30</property>
    <property name="maxPoolSize">100</property>
    <property name="minPoolSize">10</property>
    <property name="maxStatements">200</property>

    <user-overrides user="test-user">
      <property name="maxPoolSize">10</property>
      <property name="minPoolSize">1</property>
      <property name="maxStatements">0</property>
    </user-overrides>

  </default-config>
</c3p0-config>

con_试验
30000
30
10
30
100
10
200
10
1.
0

我也有同样的问题,我的问题是我的web应用程序容器(Tomcat)正在管理我的数据库连接。我必须将c3p0配置从persistence.xml文件移到Tomcat的context.xml文件中。如果这是您的问题,那么提供的链接是一个很好的起点。

您的设置中有一个输入错误,它应该是
空闲测试周期
而不是
空闲测试周期


有关设置的信息,请参阅本文:

Philipi Willemann是正确的,如果添加c3p0配置xml,将正确读取属性。注意:如果您添加了hibernate.config文件中已经描述的一些配置属性,hibernate将忽略它们。为了便于参考,您可以在“通过c3p0 config.xml覆盖c3p0默认值”部分的“可能重复”下找到更多信息