hibernate/hibernate-orm · error · UnsupportedOperationException
GaussDB only supports accessing REF_CURSOR parameters by pos
Error message
GaussDB only supports accessing REF_CURSOR parameters by position
What it means
Dialect.getResultSet(CallableStatement, name) is the by-name variant for retrieving REF_CURSOR out-parameters. GaussDB (per GaussDBDialect) only supports accessing refcursor parameters by position, so any code path that asks for a cursor by name throws UnsupportedOperationException immediately.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/GaussDBDialect.java:908
return SelectItemReferenceStrategy.POSITION;
}
@Override
public CallableStatementSupport getCallableStatementSupport() {
return GaussDBCallableStatementSupport.INSTANCE;
}
@Override
public ResultSet getResultSet(CallableStatement statement, int position) throws SQLException {
if ( position != 1 ) {
throw new UnsupportedOperationException( "GaussDB only supports REF_CURSOR parameters as the first parameter" );
}
return (ResultSet) statement.getObject( 1 );
}
@Override
public ResultSet getResultSet(CallableStatement statement, String name) throws SQLException {
throw new UnsupportedOperationException( "GaussDB only supports accessing REF_CURSOR parameters by position" );
}
@Override
public boolean qualifyIndexName() {
return false;
}
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return GaussDBIdentityColumnSupport.INSTANCE;
}
@Override
public boolean supportsExpectedLobUsagePattern() {
return false;
}
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- Register the REF_CURSOR parameter by position (1) instead of by name and access the result positionally
- Declare the procedure call with positional parameters throughout on GaussDB - the driver requires it for cursors
- Keep named declarations for other databases but branch the GaussDB persistence unit to a positional variant
- Verify position 1 usage at the same time - GaussDB only supports the first parameter as a cursor
Example fix
// before (named refcursor, throws on GaussDB) @NamedStoredProcedureQuery(name = "fetchRows", procedureName = "fetch_rows", parameters = @StoredProcedureParameter(name = "cur", mode = ParameterMode.REF_CURSOR)) // after (positional refcursor at position 1) @NamedStoredProcedureQuery(name = "fetchRows", procedureName = "fetch_rows", parameters = @StoredProcedureParameter(position = 1, mode = ParameterMode.REF_CURSOR))
Defensive patterns
Strategy: validation
Validate before calling
Dialect d = sessionFactory.getJdbcServices().getDialect();
if (d instanceof GaussDBDialect && hasNamedRefCursorParameter(call)) {
call = toPositionalCall(call); // name 'cur' -> position 1, ParameterMode.REF_CURSOR
} Type guard
static boolean namedRefCursorSafe(Dialect d) {
return !(d instanceof GaussDBDialect);
} Try / catch
try {
results = namedQuery.getResultList();
} catch (UnsupportedOperationException e) {
if (e.getMessage().contains("by position")) {
// re-register parameters positionally and retry
} else throw e;
} Prevention
- Prefer positional parameter registration for stored procedures in portable code
- Review @NamedStoredProcedureQuery annotations for named REF_CURSOR parameters when adding GaussDB
- Add GaussDB to the integration-test matrix for procedure-call code
When it happens
Trigger: Using named REF_CURSOR parameters with GaussDB: @NamedStoredProcedureQuery with a parameterName of ParameterMode.REF_CURSOR type, or calling StoredProcedureQuery.getResultList after registering the cursor by name - Hibernate resolves names and ends up in the by-name hook.
Common situations: Named-parameter stored-procedure code written for Oracle/PostgreSQL being pointed at GaussDB; annotation-based procedure declarations that prefer names for readability; shared persistence units across databases.
Related errors
- JDBC driver does not support named parameters for setArray.
- GaussDB only supports REF_CURSOR parameters as the first par
- Cannot mix named parameters and REF_CURSOR parameter on Post
- SingleStore does not support resultsets via stored procedure
- Unexpected error extracting REF_CURSOR parameter [{}]
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/74639aad0a448602.
Report an issue: GitHub.