When Hibernate builds session factory initially it prints an error message "Could not obtain connection metadata" and prints a SQLException stack trace if the network is not available but doesn't throw an expcetion.
When I looked at org.hibernate.cfg.SettingsFactory.buildSettings method it catches the SQLException and logs it but doesn't re-throw it, not even a HibernateExpcetion. So, I couldn't get a handle to exception and stop the process.
Is there any other way to detect the network availability before opening a seesion? Will an Exception be thrown from this method in the next release?
try {
Connection conn = connections.getConnection();
try {
DatabaseMetaData meta = conn.getMetaData();
metaSupportsScrollable = meta.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
if ( ( batchSize > 0 ) && !meta.supportsBatchUpdates() ) batchSize = 0;
if ( Environment.jvmSupportsGetGeneratedKeys() ) {
try {
Boolean result = (Boolean) DatabaseMetaData.class.getMethod("supportsGetGeneratedKeys", null).invoke(meta, null);
metaSupportsGetGeneratedKeys = result.booleanValue();
}
catch (AbstractMethodError ame) {
metaSupportsGetGeneratedKeys = false;
}
catch (Exception e) {
metaSupportsGetGeneratedKeys = false;
}
}
}
finally {
connections.closeConnection(conn);
}
}
catch (SQLException sqle) {
log.warn("Could not obtain connection metadata", sqle);
}
catch (UnsupportedOperationException uoe) {
// user supplied JDBC connections
}
[b]Hibernate version:[/b] 3.0.5
[b]Mapping documents:[/b]
[b]Code between sessionFactory.openSession() and session.close():[/b]
[b]Full stack trace of any exception that occurs:[/b]
2005-07-07 11:45:21,290 WARN main cfg.SettingsFactory Could not obtain connection metadata
java.sql.SQLException: The application requester cannot establish the connection.(No route to host: connect)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:460)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:2673)
at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:878)
at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:769)
at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:355)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:118)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
at com.hfa.jacl.persist.common.HibernateService.initialize(HibernateService.java:493)
[b]Name and version of the database you are using:[/b]
[b]The generated SQL (show_sql=true):[/b]
[b]Debug level Hibernate log excerpt:[/b]
|