HHH-8684 : Named output parameters don't work for stored procedure call

This commit is contained in:
Gail Badner 2013-11-22 16:22:36 -08:00
parent 9c96e23488
commit 5d09464c67
3 changed files with 36 additions and 30 deletions

View File

@ -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) @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(); 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();
} }

View File

@ -46,6 +46,7 @@ import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.AbstractBasicQueryContractImpl; import org.hibernate.internal.AbstractBasicQueryContractImpl;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
@ -67,7 +68,10 @@ import org.hibernate.type.Type;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements ProcedureCall, ResultContext { 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]; 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(); final List<ProcedureCallMementoImpl.ParameterMemento> storedRegistrations = memento.getParameterDeclarations();
if ( storedRegistrations == null ) { if ( storedRegistrations == null ) {
// most likely a problem if ParameterStrategy is not UNKNOWN... // 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 was [%s] on named copy [%s], but no parameters stored",
parameterStrategy, parameterStrategy,
procedureName procedureName
@ -314,9 +318,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements
.getJdbcServices() .getJdbcServices()
.getExtractedMetaDataSupport(); .getExtractedMetaDataSupport();
if ( ! databaseMetaData.supportsNamedParameters() ) { if ( ! databaseMetaData.supportsNamedParameters() ) {
throw new NamedParametersNotSupportedException( LOG.unsupportedNamedParameters();
"Named stored procedure parameters used, but JDBC driver does not support named parameters"
);
} }
parameterStrategy = ParameterStrategy.NAMED; parameterStrategy = ParameterStrategy.NAMED;
} }

View File

@ -235,31 +235,31 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
session.close(); session.close();
} }
// H2 does not support named parameters // A warning should be logged if database metadata indicates named parameters are not supported.
// @Test @Test
// public void testInParametersByName() { public void testInParametersByName() {
// Session session = openSession(); Session session = openSession();
// session.beginTransaction(); session.beginTransaction();
//
// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
// query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 ); query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 );
// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 );
// ProcedureOutputs procedureResult = query.getOutputs(); ProcedureOutputs procedureResult = query.getOutputs();
// Output currentOutput = procedureResult.getCurrent(); Output currentOutput = procedureResult.getCurrent();
// assertNotNull( currentOutput ); assertNotNull( currentOutput );
// ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput ); ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
// List results = resultSetReturn.getResultList(); List results = resultSetReturn.getResultList();
// assertEquals( 1, results.size() ); assertEquals( 1, results.size() );
// Object result = results.get( 0 ); Object result = results.get( 0 );
// assertTyping( Object[].class, result ); assertTyping( Object[].class, result );
// Integer id = (Integer) ( (Object[]) result )[0]; Integer id = (Integer) ( (Object[]) result )[0];
// String name = (String) ( (Object[]) result )[1]; String name = (String) ( (Object[]) result )[1];
// assertEquals( 1, (int) id ); assertEquals( 1, (int) id );
// assertEquals( "User 1", name ); assertEquals( "User 1", name );
//
// session.getTransaction().commit(); session.getTransaction().commit();
// session.close(); session.close();
// } }
@Test @Test
public void testInParametersByPosition() { public void testInParametersByPosition() {