I encountered this problem com.mysql.jdbc.CommunicationsException when using Hibernate + MYSQL some time ago: . . . 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. , xqnbsp;
After some research, I finally solved the problem. It turned out to be a problem with mysql timeout settings.
Specific solutions:
Method 1: Use hibernate to modify Hibernate.cfg.xml and add some parameters
<property name="connection.autoReconnect">true</property> rV Q w
<property name="connection.autoReconnectForPools">true</property> Cw vgnlI?
<property name="connection.is-connection-validation-required">true</property> 42LtkTO w
Method 2: Do not modify the database connection parameters with hibernate
Add autoRcConnect=true to the database connection parameters
Add parameters to connection url: autoReconnect=true =h6 yD*%
Method Three: Yes C3P0
<property name="hibernate.c3p0.acquire_increment">1</property> ba,oxjRa
<property name="hibernate.c3p0.idle_test_period">0</property> jUTE)lO&}
<property name="hibernate.c3p0.timeout">0</property> ]g11Q ^3;
<property name="hibernate.c3p0.validate">true</property>
This will solve the problem.
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/zm12037/archive/2009/12/30/5109240.aspx