HHH-8684 : Named output parameters don't work for stored procedure call
This commit is contained in:
parent
9c96e23488
commit
5d09464c67
|
@ -1662,4 +1662,8 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message(value = "The fetch attribute on <many-to-many> has been deprecated. Instead of fetch=\"select\", use lazy=\"extra\" with <map>, <set>, <bag>, <idbag>, or <list>, 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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ProcedureCallMementoImpl.ParameterMemento> 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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue