-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how can i find out connection status?
PostPosted: Sun Aug 19, 2007 1:39 pm 
Newbie

Joined: Mon Apr 25, 2005 2:37 am
Posts: 5
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.