com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed

后端 未结 6 2172
闹比i
闹比i 2020-11-30 00:01

I built an application and deployed locally ... and it was working perfectly. I deployed it on a remote server and started getting the exception mentioned in the subject lin

6条回答
  •  没有蜡笔的小新
    2020-11-30 00:14

    If you don't want use connection pool (you sure, that your app has only one connection), you can do this - if connection falls you must establish new one - call method .openSession() instead .getCurrentSession()

    For example:

    SessionFactory sf = null;
    // get session factory
    // ...
    //
    Session session = null;
    try {
            session = sessionFactory.getCurrentSession();
    } catch (HibernateException ex) {
            session = sessionFactory.openSession();
    }
    

    If you use Mysql, you can set autoReconnect property:

        jdbc:mysql://127.0.0.1/database?autoReconnect=true
    

    I hope this helps.

提交回复
热议问题