When I configure hibernate to connect to a DB and for some reason the connection fails, I noticed that it doesnt throw any exception neither when building the factory (which is acceptable) nor when I call sessionFactory.openSession() (which is less acceptable). What is more annoying is that session.isConnected() returns true after I call sessionFactory.openSession(). (Which is totally unacceptable).
The only hint up to that moment that tells me that it hasnt connected to the DB is a WARN log entry caused by a java.sql.SQLException that it internally catches and just sends to the logger. Besides creating a pseudo transaction to force an exception is there any other way of getting the connection status? (Maybe an option in the configuration that says "dont log the failed connection attempt, but throw a hibernate exception) . I ve searched but not found anything. Thanks a lot.
What connection pool are you using? Hibernate's built-in pool should not be used for anything other than simple tests.
Proxool, on the other hand, allows you to do exactly what you want: set test-before-use property to true and it will throw an exception if it can't find or create a suitable connection. You can even listen to connection events if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With