I have a JSF app with the DAO layer implemented for Hibernate (also using Spring for transaction management).
The problem I’m having is occasionally the database goes down and when this happens I want the JSF app to redirect to a “Lost connection to the database” page.
There’s two approaches I can think of to handle this:
(1) a phase listener that tests the database connection on every request and redirects if the database is not there; (except that means an extra database query on every web app request)
(2) have every method in every DAO throw some kind of “NoDBConnectionExcepiton” and catch that exception in the backing beans and redirect there (except that means writing a lot of exception handling code)
Does anyone have any ideas? Suggestion and advice are appreciated!
Rob
I’d go for this. You can let it be a subclass of some exception which it is already throwing, so that you don’t need to change the
throwsorcatchclauses. For example, a subclass ofSQLExceptionmaybe?Not necessarily. You can define a custom error page for a specific exception in
web.xmlso that the container will handle it by itself.