apache/shardingsphere · error · SQLFeatureNotSupportedException

getRef

Error message

getRef

What it means

SQL REF types are a rarely implemented JDBC optional feature, and ShardingSphere's federation ResultSet does not support them. getRef(int) is final in AbstractUnsupportedOperationSQLFederationResultSet and always throws SQLFeatureNotSupportedException, since federated results are flattened values with no server-side reference semantics.

Source

Thrown at kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java:175

    
    @Override
    public final NClob getNClob(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNClob");
    }
    
    @Override
    public final Reader getNCharacterStream(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNCharacterStream");
    }
    
    @Override
    public final Reader getNCharacterStream(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNCharacterStream");
    }
    
    @Override
    public final Ref getRef(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getRef");
    }
    
    @Override
    public final Ref getRef(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getRef");
    }
    
    @Override
    public final RowId getRowId(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getRowId");
    }
    
    @Override
    public final RowId getRowId(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getRowId");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. Avoid REF access under federation: restructure the schema to use ordinary foreign-key joins instead of SQL REF types.
  2. Read the underlying value with getObject/getString if the driver materializes references as addressable values, then resolve manually.
  3. Route such statements outside federation to the backing driver, whose ResultSet may implement getRef.
  4. Catch SQLFeatureNotSupportedException and degrade gracefully if the column is optional.

Example fix

// before
Ref ref = resultSet.getRef(1);

// after
Object value = resultSet.getObject(1); // resolve the reference manually
Defensive patterns

Strategy: try-catch

Validate before calling

// check column type before attempting REF access
if (resultSet.getMetaData().getColumnType(1) != Types.REF) { /* safe path */ }

Try / catch

try { Ref ref = rs.getRef(1); } catch (SQLFeatureNotSupportedException e) { log.warn("REF access unsupported under federation; column={}", 1); }

Prevention

When it happens

Trigger: Calling ResultSet.getRef(int columnIndex) on a ResultSet returned by a SQL federation query, i.e. any attempt to read a SQL REF-typed column by index through the federation engine.

Common situations: Generic JDBC tooling or migration utilities that call getRef on every column of a known REF type; schemas with SQL:1999 REF columns (mostly Oracle-style object-relational usage) queried through ShardingSphere federation.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/c9bc84cb782d7ff3. Report an issue: GitHub.