HHH-12905 Improve the error message and update the tests accordingly

Also fix a loose end in the MySQL test: at least with MariaDB, using
a bit(1) as datatype for boolean does not work: it always return true
even if you set it to 0. Using either boolean or tinyint(1) solves
the issue.

As I'm not sure older versions of MySQL supports a real boolean type I
used a tinyint(1).
This commit is contained in:
Guillaume Smet 2018-08-14 00:41:44 +02:00
parent cac2cd057b
commit 8e6fcce523
3 changed files with 8 additions and 8 deletions

View File

@ -81,10 +81,10 @@ public class ParameterBindImpl<T> implements ParameterBind<T> {
if ( procedureParameter.getParameterType() != null ) { if ( procedureParameter.getParameterType() != null ) {
if ( value == null ) { if ( value == null ) {
if ( !procedureParameter.isPassNullsEnabled() ) { if ( !procedureParameter.isPassNullsEnabled() ) {
throw new IllegalArgumentException( "The parameter with the [" + throw new IllegalArgumentException( "The parameter " +
( procedureParameter.getName() != null ( procedureParameter.getName() != null
? procedureParameter.getName() + "] name" ? "named [" + procedureParameter.getName() + "]"
: procedureParameter.getPosition() + "] position" ) : "at position [" + procedureParameter.getPosition() + "]" )
+ " was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters." ); + " was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters." );
} }
} }

View File

@ -107,11 +107,11 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
statement.executeUpdate( statement.executeUpdate(
"CREATE PROCEDURE sp_is_null (" + "CREATE PROCEDURE sp_is_null (" +
" IN param varchar(255), " + " IN param varchar(255), " +
" OUT result BIT(1) " + " OUT result tinyint(1) " +
") " + ") " +
"BEGIN " + "BEGIN " +
" IF (param IS NULL) THEN SET result = 1; " + " IF (param IS NULL) THEN SET result = true; " +
" ELSE SET result = 0; " + " ELSE SET result = false; " +
" END IF; " + " END IF; " +
"END" "END"
); );
@ -411,7 +411,7 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
fail("Should have thrown exception"); fail("Should have thrown exception");
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
assertEquals( "The parameter on the [1] position was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters.", e.getMessage() ); assertEquals( "The parameter at position [1] was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters.", e.getMessage() );
} }
}); });
} }

View File

@ -405,7 +405,7 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
fail("Should have thrown exception"); fail("Should have thrown exception");
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
assertEquals( "The parameter with the [param] name was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters.", e.getMessage() ); assertEquals( "The parameter named [param] was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters.", e.getMessage() );
} }
} ); } );
} }