Java Hibernate-一段时间后,我在AWS中获得JDBCConnectionException-

Java Hibernate-一段时间后,我在AWS中获得JDBCConnectionException-,java,hibernate,amazon-web-services,Java,Hibernate,Amazon Web Services,当我将SessionFactory设置为静态属性时,我开始出现这个异常。当我将代码推送到AWS服务器时,我不会立即得到这个异常。几天后我就拿到了。当我得到它时,我会继续得到它。当我重新启动AWS服务器时,异常消失 这是我的密码 public List<E> getAll(Class<E> c) { if (busUtil.iSessionFactory == null) busUtil.loadSessionFactory(); Ses

当我将SessionFactory设置为静态属性时,我开始出现这个异常。当我将代码推送到AWS服务器时,我不会立即得到这个异常。几天后我就拿到了。当我得到它时,我会继续得到它。当我重新启动AWS服务器时,异常消失

这是我的密码

public List<E> getAll(Class<E> c) {

    if (busUtil.iSessionFactory == null)
        busUtil.loadSessionFactory();

    Session session = busUtil.iSessionFactory.openSession();

    List<E> t = null;
    try {

        session.beginTransaction();
        t = session.createCriteria(c).list();
        session.getTransaction().commit();

    } catch (Exception e) {
        e.printStackTrace();

        new AppLogger().log("Exception" + busUtil.getStackTrace(e) , busConstant.SeveritySevere, new Object() {
        }.getClass().getEnclosingMethod().getName());

        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return t;
}
数据库配置

<hibernate-configuration>

<session-factory>

    <!-- Database connection settings -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/CURIOSITE</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">10</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

</session-factory>

com.mysql.jdbc.Driver
根
jdbc:mysql://localhost:3306/CURIOSITE
根
org.hibernate.dialogue.mysql5dialogue
10
org.hibernate.dialogue.mysql5dialogue
org.hibernate.cache.NoCacheProvider
真的
更新

摆脱此异常的一种方法是捕获此异常并在我将SessionFactory作为静态属性时重新加载SessionFactory

但有人知道我为什么会得到这个例外吗

感谢您的帮助。谢谢:“《Hibernate》自己的连接池算法还很初级。它旨在帮助您入门,而不是用于生产系统。”

其中一个原因是Hibernate不测试连接运行状况。这意味着,正如您所看到的,在不完善的网络上长期运行的连接往往会失败


c3p0
与Hibernate配合良好,允许您发布数据库连接配置。我刚刚发布了数据库配置。只是为了确认,所以我缺少Hibernate.c3p0.min\u大小,Hibernate.c3p0.max\u大小,配置文件中的hibernate.c3p0.timeout和hibernate.c3p0.max_语句属性?min/max size只是池的大小。您要查看
空闲测试时间
超时
。(注意
max_语句
是性能问题,而不是连接问题),不仅仅是添加一些属性。
<hibernate-configuration>

<session-factory>

    <!-- Database connection settings -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/CURIOSITE</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">10</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

</session-factory>