Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate failed to execute query afte 1 day

I am getting following error in my web application after one day. I have dont lot of search on it for couldn't fix this problem yet. Can anybody help me out?

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was59461 milliseconds ago.The last packet sent successfully to the server was 59461 milliseconds 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3270)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1932)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    ... 26 more
Caused by: java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3251)
    ... 36 more
like image 989
Pankaj Rastogi Avatar asked Dec 28 '22 12:12

Pankaj Rastogi


1 Answers

You need to configure hibernate to execute dummy query so that your connection stays alive .

<!--connection pool--> 
<property name="hibernate.dbcp.maxActive">10</property> 
<property name="hibernate.dbcp.whenExhaustedAction">1</property> 
<property name="hibernate.dbcp.maxWait">20000</property> 
<property name="hibernate.dbcp.maxIdle">10</property> 

<!-- prepared statement cache--> 
<property name="hibernate.dbcp.ps.maxActive">10</property> 
<property name="hibernate.dbcp.ps.whenExhaustedAction">1</property> 
<property name="hibernate.dbcp.ps.maxWait">20000</property> 
<property name="hibernate.dbcp.ps.maxIdle">10</property> 

<!-- optional query to validate pooled connections:--> 
<property name="hibernate.dbcp.validationQuery">select 1</property> 
<property name="hibernate.dbcp.testOnBorrow">true</property> 
<property name="hibernate.dbcp.testOnReturn">true</property> 
like image 185
jmj Avatar answered Dec 30 '22 06:12

jmj