Hibernate version:3.2.0.cr1
hi all,
i'd like to display an error page that says database server is down.
doing that, i'm planning to write a filter that listens all requests and asks my HibernateUtil the database connection,
and if the database server is down, the filter redirects request to the error page.
so i modified the ordinary HibernateUtil class's static block and getCurentSession method, code snippet below;
public static Session getCurrentSession() {
try {
Session sess= getSessionFactory().getCurrentSession();
HealthStatusHelper.setDatabaseRunning( true );
return sess;
}
catch( HibernateException e ) {
HealthStatusHelper.setDatabaseRunning( false );
throw e;
}
}
static {
try {
configuration= new Configuration();
configuration.configure();
if( configuration.getProperty(Environment.SESSION_FACTORY_NAME)!=null ) {
configuration.buildSessionFactory();
}
else {
sessionFactory= configuration.buildSessionFactory();
}
HealthStatusHelper.setDatabaseRunning( true );
}
catch( Throwable ex ) {
HealthStatusHelper.setDatabaseRunning( false );
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
but, this solution doesn't work, configuration.buildSessionFactory() call writes out an exception's stack trace to console that says connection refused to the database
server but doesn't throws it.
what's wrong?
|