我正在使用 JPA 和数据核,以便访问 postgresql 数据库。我的设置如下:
持久性.xml
<persistence-unit name="postgresql" >
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<class>com.something.DbClass1</class>
<class>com.something.DbClass2</class>
<exclude-unlisted-classes/>
<properties>
<property name="datanucleus.ConnectionDriverName" value="org.postgresql.Driver"/>
<property name="datanucleus.ConnectionURL" value="jdbc:postgresql://IP:5432/some_db"/>
<property name="datanucleus.ConnectionUserName" value="username"/>
<property name="datanucleus.ConnectionPassword" value="password"/>
<property name="datanucleus.connectionPoolingType" value="C3P0"/>
</properties>
</persistence-unit>
我还定义了 C3P0.properties 文件:
c3p0.minPoolSize=15
c3p0.maxPoolSize=100
c3p0.initialPoolSize=15
我正在使用这样的EntityManager:
EntityManager em = entityManager();
DbClass1 x = em.merge(input);
em.close();
现在,我在调试日志中有一些奇怪的地方。每个查询似乎都会打开/关闭连接(请参见下文):有人能指出我在这里做错了什么吗?谢谢 !
13:13:43,969 DEBUG [DataNucleus.Persistence] - Adding support for Java type boolean (persistent=true, DFG=true, embedded=true)
13:13:43,970 DEBUG [DataNucleus.Persistence] - Adding support for Java type byte (persistent=true, DFG=true, embedded=true)
13:13:43,970 DEBUG [DataNucleus.Persistence] - Adding support for Java type char (persistent=true, DFG=true, embedded=true)
...
13:13:44,738 INFO [com.mchange.v2.c3p0.C3P0Registry] - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
13:13:44,766 DEBUG [com.mchange.v2.c3p0.management.DynamicPooledDataSourceManagerMBean] - MBean: com.mchange.v2.c3p0:type=PooledDataSource[1br5qth8q1lseuas1a25ohv|38d0357a] registered.
13:13:44,781 DEBUG [DataNucleus.Connection] - Created tx data source using pooling type of C3P0
13:13:44,781 DEBUG [DataNucleus.Connection] - Registered transactional connection factory under name "rdbms/tx"
13:13:44,796 DEBUG [com.mchange.v2.c3p0.management.DynamicPooledDataSourceManagerMBean] - MBean: com.mchange.v2.c3p0:type=PooledDataSource[1br5qth8q1lseuas1a25ohv|2415a94f] registered.
13:13:44,796 DEBUG [DataNucleus.Connection] - Created nontx data source using pooling type of C3P0
13:13:44,796 DEBUG [DataNucleus.Connection] - Registered nontransactional connection factory under name "rdbms/nontx"
13:13:44,915 INFO [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource] - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1br5qth8q1lseuas1a25ohv|2415a94f, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.postgresql.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1br5qth8q1lseuas1a25ohv|2415a94f, idleConnectionTestPeriod -> 0, initialPoolSize -> 15, jdbcUrl -> jdbc:postgresql://IP:5432/some_db, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 3600, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 15, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
13:13:45,201 DEBUG [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@2a801059.acquireResource() returning.
13:13:45,203 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@695cd9c0" opened
13:13:45,205 DEBUG [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@2a801059.acquireResource() returning.
13:13:45,205 DEBUG [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@2a801059.acquireResource() returning.
13:13:45,308 DEBUG [DataNucleus.Datastore] - Adding RDBMS support for Java type java.lang.Boolean (jdbc-type=BIT, sql-type=BIT, datastore-mapping-type=org.datanucleus.store.rdbms.mapping.BitRDBMSMapping, default=true)
13:13:45,309 DEBUG [DataNucleus.Datastore] - Adding RDBMS support for Java type java.lang.Boolean (jdbc-type=CHAR, sql-type=CHAR, datastore-mapping-type=org.datanucleus.store.rdbms.mapping.CharRDBMSMapping, default=false)
13:13:45,310 DEBUG [DataNucleus.Datastore] - Adding RDBMS support for Java type java.lang.Boolean (jdbc-type=BOOLEAN, sql-type=BOOLEAN, datastore-mapping-type=org.datanucleus.store.rdbms.mapping.BooleanRDBMSMapping, default=false)
13:13:45,311 DEBUG [DataNucleus.Datastore] - Adding RDBMS support for Java type java.lang.Boolean (jdbc-type=SMALLINT, sql-type=SMALLINT, datastore-mapping-type=org.datanucleus.store.rdbms.mapping.SmallIntRDBMSMapping, default=false)
...
13:14:11,791 DEBUG [DataNucleus.Persistence] - Object "<redacted>@52c51614" being inserted into table "<redacted>""
13:14:11,791 DEBUG [DataNucleus.Connection] - Connection added to the pool : [org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl@1b78efd8, null] for key=org.datanucleus.ObjectManagerImpl@699c9f16 in factory=ConnectionFactory:nontx[org.datanucleus.store.rdbms.ConnectionFactoryImpl@29422384]
13:14:11,791 DEBUG [DataNucleus.Connection] - Setting autocommit=false to connection: com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a
13:14:11,842 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a" opened with isolation level "read-committed"
13:14:11,843 DEBUG [DataNucleus.Datastore.Persist] - Retrieving PreparedStatement for connection "com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a"
13:14:11,843 DEBUG [DataNucleus.Datastore.Native] - INSERT INTO <redacted> ...
13:14:11,843 DEBUG [DataNucleus.Datastore.Native] - INSERT INTO <redacted> ...
13:14:11,897 DEBUG [DataNucleus.Datastore.Persist] - Execution Time = 53 ms (number of rows = 1)
13:14:11,897 DEBUG [DataNucleus.Persistence] - Insert of object "<redacted>" is calling insertPostProcessing for field "<redacted>"
13:14:11,897 DEBUG [DataNucleus.Datastore.Retrieve] - Closing PreparedStatement org.datanucleus.store.rdbms.ParamLoggingPreparedStatement@3970ae0
13:14:11,990 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a" non enlisted to a transaction is being committed.
13:14:11,990 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a" closed
13:14:11,990 DEBUG [DataNucleus.Connection] - Connection removed from the pool : [org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl@1b78efd8, com.mchange.v2.c3p0.impl.NewProxyConnection@455dd32a] for key=org.datanucleus.ObjectManagerImpl@699c9f16 in factory=ConnectionFactory:nontx[org.datanucleus.store.rdbms.ConnectionFactoryImpl@29422384]