Hello,
how to test if the connection to database is valid?
I use this code (and I also use C3P0 connection pooler):
Code:
Session s = getSessionFactory().getCurrentSession();
s.beginTransaction();
s.connection().createStatement();
s.getTransaction().commit();
When no exception happened, connection is valid.
But this approcha looks ugly to me and I have also problem that when connection isn't valid, hibernate try to connect for cca. 30 seconds and entire application freezes (even if connection test runs in separate thread).
Is there any other possibility how to test it, or at least how to force hibernate to test database connection for only 5 seconds or to force hibernate not to "freeze" application?
Thank you for your answers.