{"record":{"id":"9032ef01b97e1118","repo":"apache/shardingsphere","slug":"setfetchdirection","errorCode":null,"errorMessage":"setFetchDirection","messagePattern":"setFetchDirection","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java","lineNumber":172,"sourceCode":"    \n    @Override\n    public final void clearWarnings() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"clearWarnings\");\n    }\n    \n    @Override\n    public final Reader getCharacterStream(final int columnIndex) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getCharacterStream\");\n    }\n    \n    @Override\n    public final Reader getCharacterStream(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getCharacterStream\");\n    }\n    \n    @Override\n    public final void setFetchDirection(final int direction) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"setFetchDirection\");\n    }\n    \n    @Override\n    public final int getFetchDirection() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getFetchDirection\");\n    }\n    \n    @Override\n    public final void setFetchSize(final int rows) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"setFetchSize\");\n    }\n    \n    @Override\n    public final int getFetchSize() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getFetchSize\");\n    }\n    \n    @Override","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java#L154-L190","documentation":"setFetchDirection(int) is one of the fetch-hint methods AbstractUnsupportedGeneratedKeysResultSet rejects with SQLFeatureNotSupportedException(\"setFetchDirection\") (line 172). ShardingSphere's generated-keys ResultSet iterates an in-memory iterator of key values already computed at execute time, so JDBC fetch-direction hints have no meaning and are explicitly unsupported.","triggerScenarios":"Calling resultSet.setFetchDirection(ResultSet.FETCH_FORWARD) (or REVERSE/UNKNOWN) on the ResultSet returned by getGeneratedKeys() — often done eagerly by frameworks that set hints on every result set they open (some pooling layers, Spring's JdbcTemplate variants, iBATIS).","commonSituations":"Frameworks applying uniform fetch hints (e.g. setFetchDirection(FETCH_FORWARD) as an optimization); code tuned for MySQL/PostgreSQL drivers where the call is accepted; the exception appearing only for INSERT+RETURN_GENERATED_KEYS statements after adding ShardingSphere-JDBC.","solutions":["Skip fetch-hint calls on generated-keys result sets; iteration order is fixed by the in-memory iterator.","Move the hint to the Statement (statement.setFetchDirection) if the underlying path needs it — or simply drop it for INSERT paths.","Catch SQLFeatureNotSupportedException around framework code you cannot edit and ignore it for key result sets.","Audit generic JDBC helper classes for unconditional setFetchDirection on every ResultSet."],"exampleFix":"// before\nrs.setFetchDirection(ResultSet.FETCH_FORWARD);\n\n// after\n// no call needed on generated-keys result set; iterator order is fixed\nlong id = rs.next() ? rs.getLong(1) : -1;","handlingStrategy":"try-catch","validationCode":"// apply fetch hints on the Statement before execution, never on the keys ResultSet\nPreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);","typeGuard":"private static boolean supportsFetchHints(ResultSet rs) {\n    return !rs.getClass().getName().endsWith(\"GeneratedKeysResultSet\");\n}","tryCatchPattern":"try {\n    rs.setFetchDirection(ResultSet.FETCH_FORWARD);\n} catch (SQLFeatureNotSupportedException ignore) {\n    // direction is fixed for in-memory key iteration\n}","preventionTips":["Set fetch hints on Statement, not ResultSet, for INSERT paths.","Skip hint application for single-column key result sets.","Add integration tests with the ShardingSphere driver for framework data-access layers."],"tags":["jdbc","shardingsphere","generated-keys","fetch-direction","unsupported-operation"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}