If I launch my application after it was idle for some time, I used to get below error. ( I am using Spring+Hibernate+MySQL as DB )
ERROR [org.hibernate.util.JDBCExceptionReporter]The last packet successfully received from the server was 74,188,684 milliseconds ago.
The last packet sent successfully to the server was 74,188,685 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.
org.hibernate.exception.JDBCConnectionException: could not execute query
I solved this issue by adding below to my servlet-context.xml.
<beans:property name="validationQuery" value="SELECT 1"/>
I had asked this question here which was more specific to solution.I need to know why I was getting that error.
I tried the 1st (Configure the connection string with autoReconnect=true ) and 3rd option (Configuring the connection pool to test the validity of the connection) provided in the above link and both worked. Still I dont get why in first place I was getting the error.
Here is my updated servlet-context.xml file and I am using ApacheDBCP for connection pooling.
<beans:bean id="MyID" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<beans:property name="url" value="jdbc:mysql://localhost:17761/myDB"/>
<beans:property name="username" value="myname"/>
<beans:property name="password" value="mypwd"/>
<beans:property name="maxIdle" value="5"/>
<beans:property name="maxActive" value="20"/>
<beans:property name="minIdle" value="5"/>
<beans:property name="validationQuery" value="SELECT 1"/>
</beans:bean>
Is it some connection expiry issue ? Please help me to understand.