diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index d61f940ddc..cc1e04003d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -1662,4 +1662,8 @@ public interface CoreMessageLogger extends BasicLogger { @Message(value = "The fetch attribute on has been deprecated. Instead of fetch=\"select\", use lazy=\"extra\" with , , , , or , which will only initialize entities (not as a proxy) as needed.", id = 455) void deprecatedManyToManyFetch(); + @LogMessage(level = WARN) + @Message(value = "Named parameters are used for a callable statement, but database metadata indicates named parameters are not supported.", id = 456) + void unsupportedNamedParameters(); + } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java index 848bd46617..81de6d3016 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java @@ -46,6 +46,7 @@ import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.AbstractBasicQueryContractImpl; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.persister.entity.EntityPersister; @@ -67,7 +68,10 @@ import org.hibernate.type.Type; * @author Steve Ebersole */ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements ProcedureCall, ResultContext { - private static final Logger log = Logger.getLogger( ProcedureCallImpl.class ); + private static final CoreMessageLogger LOG = Logger.getMessageLogger( + CoreMessageLogger.class, + ProcedureCallImpl.class.getName() + ); private static final NativeSQLQueryReturn[] NO_RETURNS = new NativeSQLQueryReturn[0]; @@ -196,7 +200,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements final List storedRegistrations = memento.getParameterDeclarations(); if ( storedRegistrations == null ) { // most likely a problem if ParameterStrategy is not UNKNOWN... - log.debugf( + LOG.debugf( "ParameterStrategy was [%s] on named copy [%s], but no parameters stored", parameterStrategy, procedureName @@ -314,9 +318,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements .getJdbcServices() .getExtractedMetaDataSupport(); if ( ! databaseMetaData.supportsNamedParameters() ) { - throw new NamedParametersNotSupportedException( - "Named stored procedure parameters used, but JDBC driver does not support named parameters" - ); + LOG.unsupportedNamedParameters(); } parameterStrategy = ParameterStrategy.NAMED; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/StoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/StoredProcedureTest.java index 64c11eac9a..493879b6d4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/StoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/StoredProcedureTest.java @@ -235,31 +235,31 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase { session.close(); } -// H2 does not support named parameters -// @Test -// public void testInParametersByName() { -// Session session = openSession(); -// session.beginTransaction(); -// -// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); -// query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 ); -// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); -// ProcedureOutputs procedureResult = query.getOutputs(); -// Output currentOutput = procedureResult.getCurrent(); -// assertNotNull( currentOutput ); -// ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput ); -// List results = resultSetReturn.getResultList(); -// assertEquals( 1, results.size() ); -// Object result = results.get( 0 ); -// assertTyping( Object[].class, result ); -// Integer id = (Integer) ( (Object[]) result )[0]; -// String name = (String) ( (Object[]) result )[1]; -// assertEquals( 1, (int) id ); -// assertEquals( "User 1", name ); -// -// session.getTransaction().commit(); -// session.close(); -// } +// A warning should be logged if database metadata indicates named parameters are not supported. + @Test + public void testInParametersByName() { + Session session = openSession(); + session.beginTransaction(); + + ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); + query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 ); + query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); + ProcedureOutputs procedureResult = query.getOutputs(); + Output currentOutput = procedureResult.getCurrent(); + assertNotNull( currentOutput ); + ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput ); + List results = resultSetReturn.getResultList(); + assertEquals( 1, results.size() ); + Object result = results.get( 0 ); + assertTyping( Object[].class, result ); + Integer id = (Integer) ( (Object[]) result )[0]; + String name = (String) ( (Object[]) result )[1]; + assertEquals( 1, (int) id ); + assertEquals( "User 1", name ); + + session.getTransaction().commit(); + session.close(); + } @Test public void testInParametersByPosition() {