I have a Hibernate J2SE Swing application and I would like to show user a MessageBox saying that the connection could not be established when the internet connection or the network is having troubles. I know the exception that needs to be caught –
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
But Hibernate has already handled this exception internally. So what do you guys suggest?
You could implmenent your own ConnectionProvider.
Basically whenever Hibernate needs a database connection it calls getConnection() on its configured ConnectionProvider.
you could create a subclass of the ConnectionProvider you are currently using and do something like that:
In the SessionFactory configuration you have to configure your custom ConnectionProvider like