Попытка отладки hibernate / c3p0 / postgres - PullRequest
0 голосов
/ 22 мая 2018

Я пытаюсь отладить какой-то довольно древний код, он работал.Единственное, что я думаю, изменилось - это недавнее обновление до 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

Я предполагаю, что из этого было установлено соединение с базой данных.

Моя программа генерирует следующее исключение из глубокого в потоке гибернации.

>     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 будут отлично работать вместе.Я просто предполагаю, что в моем окружении что-то нуждается в обновлении, но я не уверен, что?

1 Ответ

0 голосов
/ 23 мая 2018

Понял!

Кажется, я использовал древнюю версию драйвера jdbc postgres, то есть версию postgresql-9.1-902.jdbc4.jar, как только я заменил ее последней версией postgresql-42.2.2.jar, все стало работать как положено.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...