improve reporting of connection errors
This commit is contained in:
parent
b771afda5b
commit
d9af0eb7e1
|
@ -42,7 +42,7 @@ public class JDBCException extends HibernateException {
|
|||
* @param sql The sql being executed when the exception occurred
|
||||
*/
|
||||
public JDBCException(String message, SQLException cause, String sql) {
|
||||
super( message + " [" + sql + "]", cause );
|
||||
super( sql == null ? message : message + " [" + sql + "]", cause );
|
||||
this.message = message;
|
||||
this.sqlException = cause;
|
||||
this.sql = sql;
|
||||
|
|
|
@ -127,11 +127,12 @@ public abstract class BasicConnectionCreator implements ConnectionCreator {
|
|||
);
|
||||
|
||||
protected JDBCException convertSqlException(String message, SQLException e) {
|
||||
final String fullMessage = message + " [" + e.getMessage() + "]";
|
||||
try {
|
||||
// if JdbcServices#getSqlExceptionHelper is available, use it...
|
||||
final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||
if ( jdbcServices != null && jdbcServices.getSqlExceptionHelper() != null ) {
|
||||
return jdbcServices.getSqlExceptionHelper().convert( e, message, null );
|
||||
return jdbcServices.getSqlExceptionHelper().convert( e, fullMessage );
|
||||
}
|
||||
}
|
||||
catch (ServiceException se) {
|
||||
|
@ -140,7 +141,7 @@ public abstract class BasicConnectionCreator implements ConnectionCreator {
|
|||
|
||||
// likely we are still in the process of initializing the ServiceRegistry, so use the simplified
|
||||
// SQLException conversion
|
||||
return simpleConverterAccess.getValue().convert( e, message, null );
|
||||
return simpleConverterAccess.getValue().convert( e, fullMessage, null );
|
||||
}
|
||||
|
||||
protected abstract Connection makeConnection(String url, Properties connectionProps);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DriverConnectionCreator extends BasicConnectionCreator {
|
|||
return driver.connect( url, connectionProps );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw convertSqlException( "Error calling Driver#connect", e );
|
||||
throw convertSqlException( "Error calling Driver.connect()", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class DriverManagerConnectionCreator extends BasicConnectionCreator {
|
|||
return DriverManager.getConnection( url, connectionProps );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw convertSqlException( "Error calling DriverManager#getConnection", e );
|
||||
throw convertSqlException( "Error calling DriverManager.getConnection()", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue