私たちのサーバーでmysql接続に問題があります。 WebAppは正常に動作しますが、数時間後にmysqlとの接続からエラーが発生します。 休止状態のセッションに何か問題があると考えています。私たちが知る限り、ハイバネートが同じセッションを使用しようとする間、mysql接続は閉じられます。 おそらく、セッションを正しく終了していない可能性があります。Hibernate connection timeout
私たちはStruts 2を使用しており、すべてのセッション処理を管理するインターセプタを定義しました。 は、ここでは、コードです:あなたが見ることができるように、我々はcurrentSessionを取得しようとしている
public class OSVStrutsInterceptors implements Interceptor {
private static SessionFactory sf;
@Override
public void destroy() {
try
{
sf.getCurrentSession().close();
}
catch (HibernateException ex)
{
throw new RuntimeException(ex);
}
}
@Override
public void init() {
}
@Override
public String intercept(ActionInvocation ai) throws Exception {
sf = HibernateUtil.getSessionFactory();
Session sesion=sf.getCurrentSession();
try {
sesion.beginTransaction();
}
catch (Exception ex) {
System.out.println(new Date()+" Sesion cerrada. Obtenemos una nueva");
sesion=sf.openSession();
}
String result=ai.invoke();
sesion.getTransaction().commit();
return result;
}
}
が、できない場合、我々は新しいセッションを開きます。また、インターセプタのdestroy()メソッドでセッションを閉じます。
しかし、私たちは常にサーバー上でこのエラーを取得:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Broken pipe
STACKTRACE:
java.net.SocketException: Broken pipe