As demonstrated by the test cases in this commit, the problem comes from the SQL Server JDBC Driver, not from Hibernate. So, ordinal-based parameter binding works just fine:
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( DATABASE_NAME + ".dbo.sp_square_number" );
query.registerStoredProcedureParameter( 1, Integer.class, ParameterMode.IN );
query.registerStoredProcedureParameter( 2, Integer.class, ParameterMode.OUT );
query.setParameter( 1, 7 );
query.execute();
int result = (int) query.getOutputParameterValue( 2 );
assertEquals( 49, result );
while name-based parameter binding does not:
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( DATABASE_NAME + ".dbo.sp_square_number" );
query.registerStoredProcedureParameter( "inputNumber", Integer.class, ParameterMode.IN );
query.registerStoredProcedureParameter( "outputNumber", Integer.class, ParameterMode.OUT );
query.setParameter( "inputNumber", 7 );
query.execute();
int result = (int) query.getOutputParameterValue( "outputNumber" );
assertEquals( 49, result );
There's nothing to be fixed in Hibernate ORM about this issue. The SQL Server Driver should support both parameter binding methods. Notice that the name-based parameter binding works just fine across schemas. It just does not work across catalogs. |