gpt4 book ai didi

java - 尝试调试 hibernate/c3p0/postgres 设置

转载 作者:行者123 更新时间:2023-11-29 13:44:37 25 4
gpt4 key购买 nike

我正在尝试调试一些相当古老的代码,它曾经有效。我认为唯一发生变化的是最近升级到 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 可以很好地协同工作。我只是假设它在我的环境中需要更新,但我不确定是什么?

最佳答案

知道了!

似乎我使用的是旧版本的 postgres jdbc 驱动程序,即版本 postgresql-9.1-902.jdbc4.jar,一旦我用最新的 postgresql-42.2.2.jar 替换它,一切都开始工作正如预期的那样。

关于java - 尝试调试 hibernate/c3p0/postgres 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com