GWT,JPA,Hibernate,c3p0 - c3p0配置无效,连接池不起作用

时间:2014-01-26 15:44:23

标签: hibernate gwt jpa c3p0

我有以下persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="masterthesis">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/masterthesis" />
            <property name="javax.persistence.jdbc.user" value="root" />
             <property name="javax.persistence.jdbc.password" value="" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="update" />

            <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />

            <property name="hibernate.c3p0.min_size" value="1" />
            <property name="hibernate.c3p0.max_size" value="5" />
            <property name="hibernate.c3p0.timeout" value="300" />
            <property name="hibernate.c3p0.max_statements" value="50" />
            <property name="hibernate.c3p0.idle_test_period" value="3000" />

        </properties>
    </persistence-unit>
</persistence>

我的第一个问题是,无论我如何设置属性,日志记录始终显示相同的结果:

  • 初始化c3p0池... com.mchange.v2.c3p0.PoolBackedDataSource@fcab93bd [connectionPoolDataSource - &gt; com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@b5498d3f [acquireIncrement - &gt; 3,acquireRetryAttempts - &gt; 30,acquireRetryDelay - &gt; 1000,autoCommitOnClose - &gt; false,automaticTestTable - &gt; null,breakAfterAcquireFailure - &gt; false,checkoutTimeout - &gt; 0,connectionCustomizerClassName - &gt; null,connectionTesterClassName - &gt; com.mchange.v2.c3p0.impl.DefaultConnectionTester,debugUnreturnedConnectionStackTraces - &gt; false,factoryClassLocation - &gt; null,forceIgnoreUnresolvedTransactions - &gt; false,identityToken - &gt; 1hge1bp8z1lhb3en1xemcds | 40ffe6dc,idleConnectionTestPeriod - &gt; 0,initialPoolSize - &gt; 3,maxAdministrativeTaskTime - &gt; 0,maxConnectionAge - &gt; 0,maxIdleTime - &gt; 0,maxIdleTimeExcessConnections - &gt; 0,maxPoolSize - &gt; 15,maxStatements - &gt; 0,maxStatementsPerConnection - &gt; 0,minPoolSize - &gt; 3,nestedDataSource - &gt; com.mchange.v2.c3p0.DriverManagerDataSource@37a75972 [description - &gt; null,driverClass - &gt; null,factoryClassLocation - &gt; null,identityToken - &gt; 1hge1bp8z1lhb3en1xemcds | 2383d26e,jdbcUrl - &gt; jdbc:mysql:// localhost:3306 / masterthesis,properties - &gt; {user = ** ,autocommit = true,release_mode = auto}],preferredTestQuery - &gt; null,propertyCycle - &gt; 0,testConnectionOnCheckin - &gt; false,testConnectionOnCheckout - &gt; false,unreturnedConnectionTimeout - &gt; 0,usesTraditionalReflectiveProxies - &gt;假; userOverrides:{}],dataSourceName - &gt; null,factoryClassLocation - &gt; null,identityToken - &gt; 1hge1bp8z1lhb3en1xemcds | 169a9d0f,numHelperThreads - &gt; 3]

第二个主要问题是,当达到15个连接时,应用程序无法再连接到数据库......但是没有例外。

以下是如何将对象保存到数据库的示例:

public void persist(){
        EntityManager em = entityManager();
        try{
            em.getTransaction().begin(); 
            if(this.getItemContractId() == null){ 
                em.persist(this);
            }
            else 
            { 
                em.merge(this); 
            }
            em.flush();
            em.getTransaction().commit(); 

        }catch(Exception ex){ 
            ex.printStackTrace(); 
            em.getTransaction().rollback(); 
        }finally{
            em.close();
        }
    }

任何人都可以帮助我吗?

提前谢谢。

0 个答案:

没有答案