Java Hibernate / C3P0错误:“无法获取连接元数据。客户尝试结帐连接超时。“ [英] Java Hibernate/C3P0 error: "Could not obtain connection metadata. An attempt by a client to checkout a Connection has timed out."

查看:216
本文介绍了Java Hibernate / C3P0错误:“无法获取连接元数据。客户尝试结帐连接超时。“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一些我通过并运行的代码。它似乎使用Hibernate框架。我已经完成了大部分错误调整配置,但这一次让我陷入了僵局。



它试图连接到两个数据库:gameapp和gamelog。两者都存在。它似乎有问题连接到gamelog,但没有连接到gameapp(稍后在init中,它连接到并加载其他数据库就好了)。下面,我粘贴了错误和异常堆栈转储。



我在配置中还有其他东西,所以我还包含了该db的配置文件。我知道这是非常含糊的,但我希望有些专业人士可以看到我错过的愚蠢错误。

 < ?xml version =1.0encoding =GBK?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0 .dtd>

< hibernate-configuration>
< session-factory>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.url> jdbc:mysql://127.0.0.1:3306 / gamelog< / property>
< property name =connection.username> root< / property>
< property name =connection.password>< / property>
< property name =connection.useUnicode> true< / property>
< property name =connection.characterEncoding> UTF-8< / property>
< property name =hibernate.jdbc.batch_size> 100< / property>
< property name =jdbc.fetch_size> 1< / property>
< property name =hbm2ddl.auto> none< / property><! - update - >
< property name =connection.useUnicode> true< / property>
< property name =show_sql> true< / property>
<! - c3p0-configuration - >
< property name =hibernate.connection.provider_class> org.hibernate.connection.C3P0ConnectionProvider< / property>
< property name =hibernate.c3p0.min_size> 5< / property>
< property name =hibernate.c3p0.max_size> 10< / property>
< property name =hibernate.c3p0.timeout> 30< / property>
< property name =hibernate.c3p0.idle_test_period> 30< / property>
< property name =hibernate.c3p0.max_statements> 0< / property>
< property name =hibernate.c3p0.acquire_increment> 5< / property>
< / session-factory>
< / hibernate-configuration>

异常和堆栈跟踪:

<$ p $ WARN [org.hibernate.cfg.SettingsFactory] ​​ - 无法获取连接元数据
java.sql.SQLException:客户端尝试访问签出Connection已超时。在com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)

在com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
在com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
在org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
在org.hibernate.cfg.Configuration .buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at com.database.hibernate.util.HibernateFactory。< init>(未知源)
at com.database.hibernate.util.HibernateUtil。< clinit>(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl.initBreedGoods(Unknown Sou rce)
at com.server.databaseop.goodOp.GoodOpImpl.access $ 000(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl $ 1.run(Unknown Source)
at java .util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)$ b $ at java.util.concurrent.FutureTask $ Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent .FutureTask.runAndReset(FutureTask.java:178)
。在java.util.concurrent.ScheduledThreadPoolExecutor中$ $ ScheduledFutureTask.access 201(ScheduledThreadPoolExecutor.java:165)
。在java.util.concurrent.ScheduledThreadPoolExecutor中$ ScheduledFutureTask。运行(ScheduledThreadPoolExecutor.java:267)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java: 603)
在java.lang.Thread.run(Thread.java:636)
引起:com.mchange.v2.resourcepool.TimeoutException:客户端超时而等待获取来自com.mchange.v2.resourcepool.BasicResourcePool@ca470的资源 - 在awaitAvailable()上的超时值$ b $在com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
at com。 mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
处com.mchange.v2 com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
。 c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 18 more




另外,还有一个解决此警告的方法:

设置 hibernate.temp .use_jdbc_metadata_defaults 属性为 false



http://www.docjar.com/html/api/org/hibernate/cfg/SettingsFactory.java.html ,尽管可能会有不让Hibernate提取JDBC元数据默认值的副作用。


I'm trying to get some code I was passed up and running. It appears to use the Hibernate framework. I've gotten past most of the errors tweaking the configuration, but this one has me dead stumped.

It's trying to connect to two databases: gameapp and gamelog. Both exist. It seems to have issues connecting to gamelog, but none connecting to gameapp (later in the init, it connects to and loads other DBs just fine). Below, I've pasted the error and exception stack dump.

I imaging there's something else in the configs, so I've also included the configuration file for that db. I know this is very vague, but I'm hoping some pro can see the stupid mistake I'm missing.

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://127.0.0.1:3306/gamelog</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property   name="connection.useUnicode">true</property>     
            <property   name="connection.characterEncoding">UTF-8</property>   
        <property name="hibernate.jdbc.batch_size">100</property>
        <property name="jdbc.fetch_size">1</property>
        <property name="hbm2ddl.auto">none</property><!-- update -->
        <property name="connection.useUnicode">true</property>
        <property name="show_sql">true</property>
        <!-- c3p0-configuration -->
        <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">10</property>
        <property name="hibernate.c3p0.timeout">30</property>
        <property name="hibernate.c3p0.idle_test_period">30</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.acquire_increment">5</property>      
    </session-factory>
</hibernate-configuration>

Exception and stack trace:

2010-04-30 17:50:00,411 WARN [org.hibernate.cfg.SettingsFactory] - Could not obtain connection metadata
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
    at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
    at com.database.hibernate.util.HibernateFactory.<init>(Unknown Source)
    at com.database.hibernate.util.HibernateUtil.<clinit>(Unknown Source)
    at com.server.databaseop.goodOp.GoodOpImpl.initBreedGoods(Unknown Source)
    at com.server.databaseop.goodOp.GoodOpImpl.access$000(Unknown Source)
    at com.server.databaseop.goodOp.GoodOpImpl$1.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@ca470 -- timeout at awaitAvailable()
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    ... 18 more

解决方案

If you have set C3P0's "checkoutTimeout" property to something other than 0 you might be timing out too quickly (that was my problem, solution: bumped it to 2000 milliseconds from 500).

Alternatively, there's a workaround for this warning:

Set the hibernate.temp.use_jdbc_metadata_defaults property to false.

Found this in http://www.docjar.com/html/api/org/hibernate/cfg/SettingsFactory.java.html, though there may be side effects of not having Hibernate extract JDBC Metadata defaults.

这篇关于Java Hibernate / C3P0错误:“无法获取连接元数据。客户尝试结帐连接超时。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆