简体   繁体   English

带有 Hibernate 3.2.6/JPA 的 c3p0 连接池库 - 无法打开连接

[英]c3p0 connection pooling library with Hibernate 3.2.6/JPA - Cannot open connection

My application have two quartz jobs readning two different tables from Oracle DB in the same time.我的应用程序有两个石英作业,同时从 Oracle DB 读取两个不同的表。 I am trying to get a connection from pool using c3p0 with Hibernate and Oracle.我正在尝试使用带有 Hibernate 和 Oracle 的 c3p0 从池中获取连接。 When Tomcat 7 starts it seems like C3P0 is initialized:当 Tomcat 7 启动时,似乎 C3P0 已初始化:

2021-02-15 18:47:26,271 [INFO] Hibernate EntityManager 3.2.1.GA 2021-02-15 18:47:26,271 [信息] Hibernate EntityManager 3.2.1.GA
2021-02-15 18:47:26,290 [INFO] Hibernate Annotations 3.2.1.GA 2021-02-15 18:47:26,290 [信息] Hibernate 注释 3.2.1.GA
2021-02-15 18:47:26,299 [INFO] Hibernate 3.2.6 2021-02-15 18:47:26,299 [信息] Hibernate 3.2.6
... ...
2021-02-15 18:47:27,473 [INFO] Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; 2021-02-15 18:47:27,473 [INFO] 初始化 c3p0-0.9.1 [建于 2007 年 1 月 16 日 14:46:42; debug?调试? true;真的; trace: 10]追踪:10]
2021-02-15 18:47:27,621 [INFO] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@add8f7b3 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e6d03554 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, ... ] 2021-02-15 18:47:27,621 [INFO] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@add8f7b3 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e6d03554 [ acquireIncrement -> 1 ,acquireRetryAttempts -> 30,acquireRetryDelay -> 1000,autoCommitOnClose -> false,automaticTestTable -> null,...]

2021-02-15 18:47:28,240 [INFO] RDBMS: Oracle, version: Oracle Database 11g Release 11.1.0.0.0 - Production 2021-02-15 18:47:28,240 [INFO] RDBMS:Oracle,版本:Oracle 数据库 11g 版本 11.1.0.0.0 - 生产
2021-02-15 18:47:28,241 [INFO] JDBC driver: Oracle JDBC driver, version: 10.2.0.4.0 2021-02-15 18:47:28,241 [信息] JDBC 驱动程序:Oracle Z82269B9B71AB4A7732F6958610214C.4 驱动程序。
2021-02-15 18:47:28,280 [INFO] Using dialect: org.hibernate.dialect.Oracle10gDialect 2021-02-15 18:47:28,280 [INFO] 使用方言:org.hibernate.dialect.Oracle10gDialect

But after a few lines, it is still showing Hibernate built-in connection pool, I don't know if that's the way it should be?但是几行之后还是显示Hibernate内置连接池,不知道是不是应该这样? :

2021-02-15 18:47:37,726 [INFO] Using Hibernate built-in connection pool (not for production use!) 2021-02-15 18:47:37,726 [INFO] 使用 Hibernate 内置连接池(不用于生产!)
2021-02-15 18:47:37,726 [INFO] Hibernate connection pool size: 20 2021-02-15 18:47:37,726 [INFO] Hibernate 连接池大小:20

Anyway, after first job successful got data from Oracle DB, second job could not obtain a connection from pool because it is closed:无论如何,在第一个作业成功从 Oracle DB 获取数据后,第二个作业无法从池中获取连接,因为它已关闭:

2021-02-15 18:48:38,923 [WARN] SQL Error: 0, SQLState: null 2021-02-15 18:48:38,923 [警告] SQL 错误:0,SQLState:null
2021-02-15 18:48:38,923 [ERROR] com.mchange.v2.c3p0.PoolBackedDataSource@add8f7b3 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e6d03554 [ 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 -> 2zgg5baf1aa5t7d1frz5fs|700f6fc5, idleConnectionTestPeriod -> 3000, initialPoolSize -> 10, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections - 2021-02-15 18:48:38,923 [ERROR] com.mchange.v2.c3p0.PoolBackedDataSource@add8f7b3 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e6d03554 [ 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 -> 2zgg5baf1aa5t7d1frz5fs|700f6fc5, idleConnectionTestPeriod -> 3000, initialPoolSize -> 10, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections - > 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@2f7ccb64 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2zgg5baf1aa5t7d1frz5fs|6a16a596, jdbcUrl -> jdbc:oracle:thin:@10.129.12.158:1520:orcl, properties -> {user= , password= , autocommit=true, release_mode=auto} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; > 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@2f7ccb64 [ description -> null, driverClass -> null, factoryClassLocation - > null, identityToken -> 2zgg5baf1aa5t7d1frz5fs|6a16a596, jdbcUrl -> jdbc:oracle:thin:@10.129.12.158:1520:orcl, properties -> {user= , password= , autocommit=true, release_mode=auto} ], preferredTestQuery - > null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2zgg5baf1aa5t7d1frz5fs|63308385, numHelperThreads -> 3 ] has been closed() -- you can no longer use it. userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2zgg5baf1aa5t7d1frz5fs|63308385, numHelperThreads ->已关闭。
2021-02-15 18:48:38,923 [DEBUG] [docadmin] ccmwsWebQuartz::GenerateDocumentTypeOfRequestJob.generateDocumentTypeOfRequest() - errororg.hibernate.exception.GenericJDBCException: Cannot open connection 2021-02-15 18:48:38,923 [DEBUG] [docadmin] ccmwsWebQuartz::GenerateDocumentTypeOfRequestJob.generateDocumentTypeOfRequest() - errororg.hibernate.exception.GenericJDBCException:无法打开连接
2021-02-15 18:48:38,923 [DEBUG] ccmwsWebQuartz::GenerateDocumentTypeOfRequestJob.generateRequest(): exception: org.hibernate.exception.GenericJDBCException: Cannot open connection 1613411318923 ms. 2021-02-15 18:48:38,923 [DEBUG] ccmwsWebQuartz::GenerateDocumentTypeOfRequestJob.generateRequest():异常:org.hibernate.exception.GenericJDBCException:无法打开连接 1613411318923 毫秒。 javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestJob.generateDocumentTypeOfRequest(GenerateDocumentTypeOfRequestJob.java:165) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestJob.generateRequest(GenerateDocumentTypeOfRequestJob.java:89) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestScheduler.execute(GenerateDocumentTypeOfRequestScheduler.Z93F725A07423FE1C889F448B33D21 javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73 ) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestJob.generateDocumentTypeOfRequest(GenerateDocumentTypeOfRequestJob.java:165) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestJob.generateRequest(GenerateDocumentTypeOfRequestJob.java:89) at com.ct.contentintegration.scheduler.GenerateDocumentTypeOfRequestScheduler.执行(生成DocumentTypeOfRequestScheduler.Z93F725A07423FE1C889F448B33D21 F46Z:23) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529) F46Z:23) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.Z93F725A07423FE1C889F448B33D21F448B33D21F)
Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection引起:org.hibernate.exception.GenericJDBCException:无法打开连接

Configuration file look like this: persistence.xml配置文件如下所示: persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence 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"
    version="1.0">
    
    <persistence-unit name="jpaCcmwsWebJob">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

<!--                        RAZVOJ                               -->

        <properties>

            <property name="hibernate.connection.url" value="jdbc:oracle:thin:@10.129.12.158:1520:orcl" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

            <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />

            <property name="hibernate.connection.password" value="docadmin2010" />

            <property name="hibernate.connection.username" value="docadmin" />

            <property name="hibernate.show_sql" value="false" />
            

            
            <property name="hibernate.c3p0.acquire_increment" value="1" />
            <property name="hibernate.c3p0.min_size" value="10" />
          <property name="hibernate.c3p0.max_size" value="20" />
          <property name="hibernate.c3p0.timeout" value="300" />
          <property name="hibernate.c3p0.max_statements" value="50" />
          <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
          <property name="hibernate.c3p0.idle_test_period" value="3000" />

        </properties>

    </persistence-unit>

</persistence>

Oracle connection type is Basic . Oracle 连接类型为Basic

Any ideas what I was doing wrong?任何想法我做错了什么?

That's an old hibernate version.那是一个旧的 hibernate 版本。

Which are your dependencies for hibernate-c3p0 and c3p0? hibernate-c3p0 和 c3p0 的依赖项是什么?

Checking from another post, it seems that the connection provider class for c3p0 was org.hibernate.connection.C3P0 but was deprecated later for org.hibernate.connection.C3P0ConnectionProvider .从另一篇文章中检查,似乎 c3p0 的连接提供程序 class 是org.hibernate.connection.C3P0但后来不推荐使用org.hibernate.connection.C3P0ConnectionProvider

Maybe based on your hibernate version you should try using the older connection provider class.也许根据您的 hibernate 版本,您应该尝试使用较旧的连接提供商 class。

hibernate connection pool hibernate 连接池

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM