The last packet sent successfully to the server was > 70,400,003 milliseconds ago. is longer than the server configured
Asked Answered
A

1

0

I have below exception

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 70,400,002 milliseconds ago. The last packet sent successfully to the server was 70,400,003 milliseconds ago. 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 did some research and change persistance.xml to this

Latest

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="unicorn" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.rh.xxx</class>
    <properties>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://xxx:3306/unicorndb?zeroDateTimeBehavior=convertToNull"/>
      <property name="hibernate.connection.password" value="xxx"/>
      <property name="hibernate.connection.username" value="student"/>
      <property name="hibernate.c3p0.max_size" value="100" />  <!--max number of JDBC connections -->
      <property name="hibernate.c3p0.min_size" value="10" />   <!--minimum number of JDBC connections-->
      <property name="hibernate.c3p0.idle_test_period" value="500" />
      <property name="hibernate.c3p0.acquire_increment" value="1" />
    </properties>
  </persistence-unit>
</persistence>

Did the latest code looked correct?

Any help would be appreciated

Anesthesiologist answered 30/10, 2017 at 8:50 Comment(3)
you decided to change JPA provider just because your database isn't responding?! (and then had a load of Hibernate persistence properties when using EclipseLink originally, which would be ignored).Communal
@DN1 check my post again.ThanksAnesthesiologist
You were originally using eclipselink, and dont post what the persistence.xml was. You are now using hibernate and dont post any exceptions for that case. So what is the problem now????Communal
W
0

To start, keep your testing simple, just use

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

instead of the idle Connection check. See c3p0 docs on Connection testing

If the problem, um, persists then the issue isn't likely to be Connections held by the pool, but some Connection or Connections that your application is checking out and holding open for an indefinite period. Ideally, Connections should be checked out, used, then checked in immediately (and robustly, using try-with-resources or a careful finally block).

Wag answered 30/10, 2017 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.