播放 2.3 JPA Hibernate MySQL Pooling/Connection 错误

Play 2.3 JPA Hibernate MySQL Pooling/Connection Error

我正在使用 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

非常感谢您的帮助!

我不知道如何使用 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" />

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

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

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

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