13

我正在尝试获取一些我通过并运行的代码。它似乎使用了 Hibernate 框架。我已经克服了大多数调整配置的错误,但这一个让我难住了。

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

我想象配置中还有其他东西,所以我还包含了该数据库的配置文件。我知道这很模糊,但我希望一些专业人士能看到我错过的愚蠢错误。

<?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>

异常和堆栈跟踪:

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
4

3 回答 3

8

如果您将 C3P0 的“checkoutTimeout”属性设置为 0 以外的值,您可能会超时太快(这是我的问题,解决方案:将其从 500 提高到 2000 毫秒)。

或者,此警告有一个解决方法:

hibernate.temp.use_jdbc_metadata_defaults属性设置为false

在http://www.docjar.com/html/api/org/hibernate/cfg/SettingsFactory.java.html中找到了这个,尽管没有 Hibernate 提取 JDBC 元数据默认值可能会有副作用。

于 2010-11-19T22:56:14.190 回答
1

实际上,这甚至不是身份验证错误。MySQL 是否正在运行或绑定到本地主机?

telnet 127.0.0.1 3306 有效吗?如果是这样,请在盒子上安装mysql客户端并尝试

mysql --user=root --ip=127.0.0.1 看看会发生什么

于 2010-05-01T02:15:27.607 回答
0

检查您是否可以在命令行上使用 root 用户和无密码 (!) 连接到 gamelog mysql 数据库。作为旁注,我建议为 root 设置密码并使用不同的帐户从您的应用程序连接到数据库,但这是另一回事。

于 2010-04-30T18:51:39.050 回答