From 5387ffc7179d1ba5e2f7573119aa697daa0b8215 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 10 Jan 2018 09:41:59 +0000 Subject: [PATCH] HHH-12136 - Fix REF_CURSOR StoredProcedure Hibernate Type not known issue --- .../internal/ProcedureParameterImpl.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/procedure/internal/ProcedureParameterImpl.java b/hibernate-core/src/main/java/org/hibernate/query/procedure/internal/ProcedureParameterImpl.java index a82ff7ec07..009dd447bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/procedure/internal/ProcedureParameterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/procedure/internal/ProcedureParameterImpl.java @@ -349,42 +349,52 @@ public class ProcedureParameterImpl if ( mode == ParameterMode.IN ) { throw new ParameterMisuseException( "IN parameter not valid for output extraction" ); } - - final Type hibernateType = determineHibernateType(); - final int[] sqlTypes = hibernateType.sqlTypes( procedureCall.getSession().getFactory() ); - - // TODO: sqlTypesToUse.length > 1 does not seem to have a working use case (HHH-10769). - // For now, if sqlTypes.length > 1 with a named parameter, then extract - // parameter values by position (since we only have one name). - final boolean useNamed = sqlTypes.length == 1 && - procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && - canDoNameParameterBinding( hibernateType ); - try { - if ( ProcedureParameterExtractionAware.class.isInstance( hibernateType ) ) { - if ( useNamed ) { - return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( - statement, - new String[] { getName() }, - procedureCall.getSession() - ); - } - else { - return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( - statement, - startIndex, - procedureCall.getSession() - ); - } - } - else { - if ( useNamed ) { + if ( mode == ParameterMode.REF_CURSOR ) { + if ( procedureCall.getParameterStrategy() == ParameterStrategy.NAMED ) { return (T) statement.getObject( name ); } else { return (T) statement.getObject( startIndex ); } } + else { + final Type hibernateType = determineHibernateType(); + final int[] sqlTypes = hibernateType.sqlTypes( procedureCall.getSession().getFactory() ); + + // TODO: sqlTypesToUse.length > 1 does not seem to have a working use case (HHH-10769). + // For now, if sqlTypes.length > 1 with a named parameter, then extract + // parameter values by position (since we only have one name). + final boolean useNamed = sqlTypes.length == 1 && + procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && + canDoNameParameterBinding( hibernateType ); + + + if ( ProcedureParameterExtractionAware.class.isInstance( hibernateType ) ) { + if ( useNamed ) { + return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( + statement, + new String[] { getName() }, + procedureCall.getSession() + ); + } + else { + return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( + statement, + startIndex, + procedureCall.getSession() + ); + } + } + else { + if ( useNamed ) { + return (T) statement.getObject( name ); + } + else { + return (T) statement.getObject( startIndex ); + } + } + } } catch (SQLException e) { throw procedureCall.getSession().getFactory().getSQLExceptionHelper().convert(