From 8e6fcce523698018a1e9952a8cf3a78485458ac7 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 14 Aug 2018 00:41:44 +0200 Subject: [PATCH] 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). --- .../hibernate/procedure/internal/ParameterBindImpl.java | 6 +++--- .../test/procedure/MySQLStoredProcedureTest.java | 8 ++++---- .../test/procedure/PostgreSQLStoredProcedureTest.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterBindImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterBindImpl.java index 6b7d99bb51..e5536efd32 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterBindImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterBindImpl.java @@ -81,10 +81,10 @@ public class ParameterBindImpl implements ParameterBind { if ( procedureParameter.getParameterType() != null ) { if ( value == null ) { if ( !procedureParameter.isPassNullsEnabled() ) { - throw new IllegalArgumentException( "The parameter with the [" + + throw new IllegalArgumentException( "The parameter " + ( procedureParameter.getName() != null - ? procedureParameter.getName() + "] name" - : procedureParameter.getPosition() + "] position" ) + ? "named [" + procedureParameter.getName() + "]" + : "at position [" + procedureParameter.getPosition() + "]" ) + " was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters." ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java index 9e9261c8f9..69e0d005b6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java @@ -107,11 +107,11 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas statement.executeUpdate( "CREATE PROCEDURE sp_is_null (" + " IN param varchar(255), " + - " OUT result BIT(1) " + + " OUT result tinyint(1) " + ") " + "BEGIN " + - " IF (param IS NULL) THEN SET result = 1; " + - " ELSE SET result = 0; " + + " IF (param IS NULL) THEN SET result = true; " + + " ELSE SET result = false; " + " END IF; " + "END" ); @@ -411,7 +411,7 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas fail("Should have thrown exception"); } 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() ); } }); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/procedure/PostgreSQLStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/procedure/PostgreSQLStoredProcedureTest.java index e544c2e34e..a4c157ab6a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/procedure/PostgreSQLStoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/procedure/PostgreSQLStoredProcedureTest.java @@ -405,7 +405,7 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe fail("Should have thrown exception"); } 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() ); } } ); }