C3P0配置!在哪里和如何? [英] C3P0 Configurations! Where and How?
问题描述
$ b
persistence.xml:
< persistence xmlns =http://java.sun.com/xml/ns/persistenceversion =2.0>
< persistence-unit name =MyPUtransaction-type =RESOURCE_LOCAL>
<! - 实体类 - >
<属性>
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQL5InnoDBDialect/>
< property name =hibernate.show_sqlvalue =true/>
< property name =bytecode.providervalue =org.hibernate.bytecode.javassist.BytecodeProviderImpl/>
< property name =hibernate.connection.usernamevalue ={username}/>
< property name =hibernate.connection.passwordvalue ={password}/>
< property name =hibernate.hbm2ddl.autovalue =update/>
< property name =hibernate.format_sqlvalue =true/>
< property name =hibernate.connection.urlvalue ={jdbc url}/>
< property name =hibernate.c3p0.min_sizevalue =1/>
< property name =hibernate.c3p0.timeoutvalue =1000/>
< property name =hibernate.c3p0.acquire_incrementvalue =1/>
< property name =hibernate.c3p0.idle_test_periodsvalue =600/>
< property name =hibernate.c3p0.testConnectionOnCheckinvalue =true/>
< property name =hibernate.c3p0.preferredTestQueryvalue =SELECT 1;/>
< / properties>
< / persistence-unit>
< /余辉>
连接池配置有问题。看起来这些配置没有任何影响,连接将在8小时后中断。
是否需要其他配置文件,如hibernate.cfg.xml或hibernate.properties?
欢迎任何帮助。
我把这个问题与我在persistence.xml中放置的属性并不影响c3p0。
<阅读 http://www.mchange.com/projects/c3p0/index .html#configuration_files 我试图把名为
c3p0-config.xml
的xml文件放在 WEB-INF / classes
,它完美地工作。 下面是一个 c3p0-config.xml
file:
< 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>
We are implementing a Web App using JPA2.0 and Hibernate3.0. Connection pool configurations are set in persistence.xml located in META-INF folder.
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>
We have a problem with connection pool configurations. It seems the configurations have no effect and the connection will be broken after 8 hours. Do we need another configuration file like hibernate.cfg.xml or hibernate.properties?
Any help is welcomed.
I had this same problem with the proprieties that I put in persistence.xml didn't affect c3p0.
Looking into http://www.mchange.com/projects/c3p0/index.html#configuration_files I tried to put an xml file named c3p0-config.xml
and put it in WEB-INF/classes
and it work perfectly.
Here is an example of a c3p0-config.xml
file:
<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>
这篇关于C3P0配置!在哪里和如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!