出現錯誤SQL Error: SQLState: S
Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
SocketException
MESSAGE: Software caused connection abort: socket write error
STACKTRACE:
SocketException: Software caused connection abort: socket write error
** END NESTED EXCEPTION **
Last packet sent to the server was ms ago
問題出現原因
mysql默認為小時後自動消除空閒連接而hibernate默認空連接超時時間大於這個數
解決方法
找到mysql目錄下的myini文件在最底處(或任意位置)添加wait_timeout =(為自定義值)
用cp代替hibernate的連接池cpjar可從hibernate開源項目的lib下面找到將其拷貝到webinf/lib下面在hibernatecfgxml配置文件中添加以下信息
<property name=hibernatecpmin_size></property>
<property name=hibernatecptimeout></property>
<property name=hibernatecpmax_statements></property>
<property name=hibernatecpidle_test_period></property>
<property name=hibernatecpacquire_increment></property>
<property name=hibernatecpvalidate>false</property>
其中hibernatecptimeout屬性指定多少秒後連接超時連接池會自動對超時連接進行重查
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26340.html