【问题标题】:Play 2.3 JPA Hibernate MySQL Pooling/Connection Error播放 2.3 JPA Hibernate MySQL 池化/连接错误
【发布时间】:2015-04-14 23:03:52
【问题描述】:

我正在使用 JPA/Hibernate 开发 Play 2.3 应用程序,并为此使用 Heroku/ClearDB.com MySQL 数据库,但在应用程序成功连接到数据库后,我收到以下错误:

[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection to jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532 Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null.Message:User 'badd25925bdd5f' has exceeded the 'max_user_connections' resource (current value: 10)

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: User 'badd25925bdd5f' has exceeded the 'max_user_connections' resource (current value: 10)

我几乎尝试了我在其他帖子上看到的所有内容,但没有任何帮助...我认为这与池化有关...?

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532?reconnect=true"/>
            <property name="javax.persistence.jdbc.user" value="badd25925bdd5f"/>
            <property name="javax.persistence.jdbc.password" value="XXX"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.c3p0.min_size" value="2"/>
            <property name="hibernate.c3p0.max_size" value="9"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="3000"/>
        </properties>
    </persistence-unit>
</persistence>

application.conf(相关部分)

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532"
db.default.user="badd25925bdd5f"
db.default.password="XXX"

jpa.default=defaultPersistenceUnit

非常感谢您的帮助!

【问题讨论】:

    标签: mysql hibernate jpa playframework playframework-2.0


    【解决方案1】:

    我不知道如何使用 Hibernate,但使用 Ebean,默认情况下连接池由 BoneCP 管理。尝试在您的application.conf 中配置它:

    # Max connections = partitionCount * maxConnPerPartition
    db.default.partitionCount=2
    db.default.maxConnectionsPerPartition=5
    

    或在您的persistence.xml

        <property name="bonecp.partitionCount" value="2" />
        <property name="bonecp.maxConnectionsPerPartition" value="5" />
    

    【讨论】:

      【解决方案2】:

      错误表明您使用的连接数比您的计划多。所以您可以

      1. 升级你的数据库计划见https://addons.heroku.com/cleardb#ignite

      2. 您可以尝试缩小您的应用程序,请参阅https://devcenter.heroku.com/articles/scaling

      【讨论】:

      • 这可能有助于摆脱这个问题,但不能回答我的问题。我要求以编程方式限制连接 - 通常应该如何工作......
      【解决方案3】:

      这个问题的解决方案(对于 Play 2.3)是将 play-hikaricp 库添加到应用程序中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-16
        • 2010-10-25
        • 2015-12-04
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多