Skip to content

Fix StoredProcedureItemReader open failure when update counts precede a ResultSet - #5536

Open
noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix-storedprocedureitemreader
Open

noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix-storedprocedureitemreader

Conversation

@noojung

@noojung noojung commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problem

StoredProcedureItemReader fails during open() when a stored procedure returns an update count before its ResultSet and no REF CURSOR is configured.

In openCursor(), a false return value from CallableStatement.execute() is incorrectly treated as indicating an OUT cursor. However, false can also mean that the first result is an update count or that there are no results. With refCursorPosition defaulting to 0, the reader calls getObject(0), causing initialization to fail.

The HSQLDB procedures used by the tests reproduce this issue by returning an update count of 0 before their ResultSet:

Invalid argument in JDBC call: parameter index out of range: 0

Fix

Skip update counts to locate the first ResultSet in the JDBC result chain. Stop once the ResultSet is found so it remains available for the reader.

Preserve the existing handling of immediate ResultSets, function return values, and configured REF CURSOR parameters.

If the result chain ends without a ResultSet, close the resources and fail during open() with a descriptive exception.

Tests

Restore the disabled stored procedure tests by moving the procedures to a script declared with separator="/", so the semicolons inside BEGIN ATOMIC are no longer treated as script statement separators.

Add unit tests for result chain traversal, missing results, resource cleanup, and existing cursor handling.

CallableStatement.execute() can return false when an update count
precedes a ResultSet. Without a configured OUT cursor, the reader
previously called getObject(0) and failed.

Skip update counts to locate the first ResultSet while preserving
function and OUT cursor handling.

Restore the disabled stored procedure tests and add unit tests for
result chain traversal and resource cleanup. Order procedure results
by ID for deterministic reads and restarts.

Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
@noojung noojung changed the title Fix StoredProcedureItemReader result handling Fix StoredProcedureItemReader open failure when update counts precede a ResultSet Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant