Hi, I currently cannot get the hibernate query timeout to work. Also once it is working (hopefully) I'm not sure which exception to catch to differentiate between a real database exception vs the timeout. We have a requirement to time out and instruct user to refine their search. Since this is a configurable timeout and different for different pages we cannot use the container's datasource settings as those would effect entire app. Env and code is below, any help is greatly appreciated.
Hibernate 3.x Websphere 7.x Java 6 Oracle 10g
List<Object[]> resultSet = null; Session session = null; try { session = getSession(); Query sqlQuery = session.createSQLQuery(argQuery); pm.bindParameters(sqlQuery); sqlQuery.setTimeout(argCriteria.getQueryTimeoutSeconds()); resultSet = sqlQuery.list(); }catch(DataAccessResourceFailureException dae){ String errMsg = "Problem running query: " + argQuery + "\nerror=" + dae.getMessage(); LOGGER.error(errMsg, dae); throw new OBSServiceException(errMsg, dae); }catch(IllegalStateException ie){ String errMsg = "Problem running query: " + argQuery + "\nerror=" + ie.getMessage(); LOGGER.error(errMsg, ie); throw new OBSServiceException(errMsg, ie); }catch(HibernateException he){ //TODO how do we tell if its a timeout exception //if(queryTimeOut) // throw OBSQueryTimeoutException() String errMsg = "Problem running query: " + argQuery + "\nerror=" + he.getMessage(); LOGGER.error(errMsg, he); throw new OBSServiceException(errMsg, he); }finally{ if(session != null) releaseSession(session); }
|