Hibernate не смог выполнить запрос после 1 дня - PullRequest
4 голосов
/ 14 октября 2011

Я получаю следующую ошибку в своем веб-приложении через один день. Я не много поиска по этому вопросу, потому что не мог решить эту проблему еще. Кто-нибудь может мне помочь?

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

1 Ответ

10 голосов
/ 14 октября 2011

Вам нужно настроить hibernate для выполнения фиктивного запроса, чтобы ваше соединение оставалось живым.

<!--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> 
...