Getting error from hibernate connection pool

129 Views Asked by At

Hi following is my hibernate.cfg.xml file

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

Initially after deployment it works fine. But after some sometime tomcat server throws following error:

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.

I am unable to figure out what wrong I have done. Please help

1

There are 1 best solutions below

0
Steve Waldman On

Connection testing might help.

You could just add

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

or for richer advice, check here.