Testing my application I decided to shutdown the database.
public Object getEntityById(Class<?> clazz, Object _id) throws PersistenceServiceException {
Object o = null;
try {
o = entityManager.find(clazz, _id);
} catch (Exception e) {
throw new PersistenceServiceException(e);
}
return o;
}
so, any database exception should be passed to the caller.
and in the controller I have
try {
template = (Template)persistenceService.getEntityById(Template.class, id);
} catch (PersistenceServiceException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setStatusMessage("INTERNAL SERVER ERROR");
response.setData(e);
return response;
}
when debugging, I can see the DatabaseException been throw.
but in servlet-context, once I have this...
<beans:bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<beans:property name="defaultErrorView" value="core/error.uncatched" />
</beans:bean>
it keeps treating the above error as unhandled.
How can I catch it on the controller? Why is it happening?
The Exception
ERROR: org.springframework.transaction.interceptor.TransactionInterceptor - **Application exception overridden by commit exception**
com.company.exceptions.PersistenceServiceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20130619-7d05127): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure