我正在尝试调试一些相当古老的代码,它曾经工作过。我认为唯一改变的是最近升级到Java 9和postgres 10.4。 配置数据库,以便使用密码进行连接,例如
psql -d med
我的hibernate.cfg.xml设置为
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="dialect"> org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/med</property>
<!-- configuration pool via c3p0-->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">60</property> <!-- seconds -->
<property name="hibernate.c3p0.timeout">3600</property> <!-- seconds -->
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<!-- <property name="hibernate.connection.autocommit">true</property> -->
</session-factory>
</hibernate-configuration>
在postgres中启动登录信息会生成[重复约30次]
2018-05-21 21:20:19.591 BST [8208] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35782 2018-05-21 21:20:19.591 BST [8209] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35784 2018-05-21 21:20:19.591 BST [8208] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:19.591 BST [8207] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35780 2018-05-21 21:20:19.592 BST [8207] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:19.592 BST [8209] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:19.595 BST [8210] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35786 2018-05-21 21:20:19.595 BST [8210] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:20.577 BST [8211] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35792 2018-05-21 21:20:20.577 BST [8212] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35788 2018-05-21 21:20:20.577 BST [8211] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:20.577 BST [8213] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35789 2018-05-21 21:20:20.577 BST [8212] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:20.578 BST [8213] dp@med LOG: connection authorized: user=dp42 database=med 2018-05-21 21:20:20.588 BST [8214] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35795 2018-05-21 21:20:20.589 BST [8215] [unknown]@[unknown] LOG: connection received: host=127.0.0.1 port=35796
我假设已经建立了与数据库的连接。
我的程序在hibernate线程中从深层生成以下异常。
> INFO: HHH000021: Bytecode provider name : javassist
May 21, 2018 9:19:18 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
May 21, 2018 9:19:18 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
May 21, 2018 9:19:18 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
May 21, 2018 9:19:18 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Processing xml file rwmed.xml xsd rwmed.xsd
May 21, 2018 9:19:19 PM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
May 21, 2018 9:19:19 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/med
May 21, 2018 9:19:19 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {}
May 21, 2018 9:19:19 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000006: Autocommit mode: false
May 21, 2018 9:19:19 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
May 21, 2018 9:19:19 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2-pre5 [built 29-September-2012 19:59:04 +0000; debug? true; trace: 10]
May 21, 2018 9:19:19 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@a3f6b143 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@b9285f39 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx9v10q2i60b0rtta|49ec71f8, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 3600, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@862ead5a [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> z8kfsx9v10q2i60b0rtta|2145b572, jdbcUrl -> jdbc:postgresql://localhost:5432/med, properties -> {} ], preferredTestQuery -> null, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> z8kfsx9v10q2i60b0rtta|59662a0b, numHelperThreads -> 3 ]
May 21, 2018 9:19:49 PM com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@6fa60d2c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
org.postgresql.util.PSQLException: This ResultSet is closed.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2839)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.setFetchSize(AbstractJdbc2ResultSet.java:1874)
at org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:37)
at org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:219)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1812)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
at org.postgresql.jdbc2.AbstractJdbc2Connection.execSQLUpdate(AbstractJdbc2Connection.java:366)
at org.postgresql.jdbc2.AbstractJdbc2Connection.getTransactionIsolation(AbstractJdbc2Connection.java:883)
at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:107)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:160)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:133)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:635)
我假设在c3p0和hibernate之间出现了问题。
我是否可以使用任何调试设置来查找实际发生的情况?我知道Java 9和Postgres 10可以很好地协同工作。我只是假设我的环境需要更新,但我不确定是什么?
答案 0 :(得分:0)
知道了!
我似乎正在使用一个古老版本的postgres jdbc驱动程序,即版本postgresql-9.1-902.jdbc4.jar,一旦我用最新的postgresql-42.2.2.jar替换它,一切都开始工作了正如所料。