mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 04:08:19 +00:00
improve reporting of connection errors
This commit is contained in:
parent
7463ce89e3
commit
2edd192b8d
@ -42,7 +42,7 @@ public JDBCException(String message, SQLException cause) {
|
||||
* @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 JDBCException convert(SQLException sqlException, String message, String s
|
||||
);
|
||||
|
||||
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 @@ protected JDBCException convertSqlException(String message, SQLException e) {
|
||||
|
||||
// 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 @@ protected Connection makeConnection(String url, Properties connectionProps) {
|
||||
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 @@ protected Connection makeConnection(String url, Properties connectionProps) {
|
||||
return DriverManager.getConnection( url, connectionProps );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw convertSqlException( "Error calling DriverManager#getConnection", e );
|
||||
throw convertSqlException( "Error calling DriverManager.getConnection()", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user