Can I do a reconnection in my execption handling to all of the database operations? Do I need to rebuild the session factory?
Example below:
public abstract class AbstractEntityDao { ... final public List<Object[]> select(String inSql, String whereClause) { ... Retry connection 5 times in while
while (retryConn) { try{ session = HibernateSessionFactory.currentSession(); tx = session.beginTransaction(); Query objQuery = session.createSQLQuery(); res = objQuery.list(); retryConn = false;
} catch (JDBCConnectionException e) { if(numOfRetries <= 5) { tx.rollback(); session.close(); numOfRetries++; retryConn = true; } } catch (Exception e) { retryConn = false; log.error(e.getMessage(), e); } } // end while }
Thanks
|