从休眠连接池获取错误

问题描述 投票:0回答:1

您好,以下是我的 hibernate.cfg.xml 文件

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Connection settings -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db_abc</property>
        <property name="connection.autoReconnect">true</property>
        <property name="hibernate.connection.username">user_abc</property>
        <property name="hibernate.connection.password">pass_abc</property>

        
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.acquire_increment">5</property>
        <property name="hibernate.c3p0.timeout">1800</property>
        
        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

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

        <!-- Drop and re-create all database on startup -->
        <property name="hibernate.hbm2ddl.auto">update</property>
        
        
        <property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>

        <!-- Annotated entity classes -->
        <mapping class="com.entity.tbl_user"/>
    </session-factory>
</hibernate-configuration>

最初部署后它工作正常。但是过了一段时间 tomcat 服务器抛出以下错误:

04-May-2023 10:55:02.389 WARN [https-jsse-nio-443-exec-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 0, SQLState: 08S01
04-May-2023 10:55:02.390 ERROR [https-jsse-nio-443-exec-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions The last packet successfully received from the server was69680 seconds ago.The last packet sent successfully to the server was 69680 seconds ago, which  is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

我无法弄清楚我做错了什么。请帮助

java hibernate datasource c3p0
1个回答
0
投票

连接测试可能有帮助。

你可以添加

<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>

或获取更丰富的建议,请查看此处

© www.soinside.com 2019 - 2024. All rights reserved.