Reset PreparedStatement.maxRows on pooled statements - #737
Open
toaditi wants to merge 1 commit into
Open
Conversation
EntityFindBuilder.makePreparedStatement only set maxRows when a positive value was requested, and never reset it otherwise. With Bitronix prepared statement caching (setPreparedStatementCacheSize(100)) a pooled statement retained the maxRows from a prior find, so a later find with the same SQL and no maxRows inherited the stale limit -- silently truncating results (and on H2 throwing, because the default fetchSize=100 then exceeds maxRows). Always call setMaxRows (0 = no limit), mirroring the always-set fetchSize handling on the following line. Adds an EntityFindTests regression test that reproduces the pooled-statement leak.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
EntityFindBuilder.makePreparedStatement()setsmaxRowsonly when a positive value is requested, and never resets it otherwise:The default transaction manager caches prepared statements —
TransactionInternalBitronixcallssetPreparedStatementCacheSize(100). JDBC'smaxRowsis statement-level state that survives statement caching, so aPreparedStatementreturned from the pool keeps themaxRowsset by a prior find. A later find with the same SQL but nomaxRowsthen inherits the stale limit:maxRows=20leaves20on the pooled statement; the next unbounded find with the same SQL returns at most 20 rows).fetchSize <= maxRows: the next find's defaultsetFetchSize(100)throwsInvalid value "100" for parameter "rows"because the stalemaxRowsis smaller.Fix
Always call
setMaxRows, using0(JDBC "no limit") when no positive value is requested — mirroring the always-setsetFetchSizehandling on the very next line, which already avoids this exact trap:This is the only site that calls
setMaxRows, and it is shared by the list/iterator and count paths, so the reset covers all finds.Testing
Adds
EntityFindTests > "maxRows does not leak onto pooled PreparedStatement", using the non-cachedTestEntityso the finds actually build and execute a pooled statement: a first find with.maxRows(2)followed by an identical-SQL find with nomaxRowsmust return the full result set. The test fails before the change (on H2, throwsInvalid value "100" for parameter "rows"on the second find) and passes after. A full:framework:testrun showed no regressions.