apache/shardingsphere · error · SQLFeatureNotSupportedException

getObject with type

Error message

getObject with type

What it means

JDBC 4.1 added getObject(int, Class<T>) for typed column conversion, but ShardingSphere's federation ResultSet only implements the untyped getObject. The typed variant is final and throws SQLFeatureNotSupportedException('getObject with type') for every target type.

Source

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

    
    @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
    public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with type");
    }
    
    @Override
    public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with type");
    }
    
    @Override
    public final Object getObject(final String columnLabel, final Map<String, Class<?>> map) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with map");
    }
    
    @Override
    public final Object getObject(final int columnIndex, final Map<String, Class<?>> map) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with map");
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Read with the classic typed accessor (getDate/getTimestamp/getString) and convert with valueOf/map helpers, e.g. rs.getTimestamp(1).toLocalDateTime().
  2. Register an ORM converter/type handler so the framework uses classic accessors for federation queries.
  3. Exclude the statement from federation so the native driver (JDBC 4.2-capable) ResultSet is used.
  4. Centralize the fallback in one row-mapper utility so callers never emit typed getObject.

Example fix

// before
LocalDate date = resultSet.getObject(1, LocalDate.class);

// after
LocalDate date = resultSet.getDate(1).toLocalDate();
Defensive patterns

Strategy: fallback

Validate before calling

// prefer classic typed accessors when running under ShardingSphere federation
boolean federation = resultSet.getClass().getName().contains("sqlfederation");

Try / catch

try { date = rs.getObject(1, LocalDate.class); } catch (SQLFeatureNotSupportedException e) { date = rs.getDate(1).toLocalDate(); }

Prevention

When it happens

Trigger: Calling ResultSet.getObject(1, LocalDate.class), getObject(1, Optional.class), or any typed getObject(int, Class) on a federation ResultSet. Java-8-date-and-time ORMs and JPA converters frequently emit this call.

Common situations: JDBC 4.2 code paths (java.time conversions) reused under ShardingSphere federation; Hibernate 5+/JPA providers converting columns to LocalDate/Instant; upgrading a datasource to federation without testing date-heavy read paths.

Related errors


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