Skip to content

[OPENJPA-2986] Let setTimeout(null) clear a query timeout - #169

Merged
rzo1 merged 2 commits into
masterfrom
OPENJPA-2986
Sep 2, 2026
Merged

[OPENJPA-2986] Let setTimeout(null) clear a query timeout#169
rzo1 merged 2 commits into
masterfrom
OPENJPA-2986

Conversation

@rzo1

@rzo1 rzo1 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Query.setTimeout(null) passed the null straight to setHint(), which drove it through FetchConfigurationImpl.setHint() into a reflective call of setQueryTimeout(int) and failed with a bad-hint-value IllegalArgumentException. So a timeout set through this API could never be cleared — on queries it did not silently ignore the null, it threw — and getTimeout() kept reporting the stale value.

A null timeout now restores the timeout the query inherits from its entity manager, which is what the query would have used had setTimeout() never been called. Deliberately not FetchPlan.DEFAULT, which resolves to the OpenJPAConfiguration value and would discard an entity-manager-scoped timeout the caller never set here.

getTimeout() reports the effective fetch plan value rather than the recorded hint, so it cannot disagree with what the query will actually use, and StoredProcedureQueryImpl delegates both methods to its query so the two cannot drift apart.

EntityManagerImpl carries a setTimeout/getTimeout pair too, but those implement EntityTransaction — a transaction timeout in seconds — and are left alone here.

Query.setTimeout(null) passed the null straight to setHint(), which drove
it through FetchConfigurationImpl.setHint() into a reflective call of
setQueryTimeout(int) and failed with a bad-hint-value
IllegalArgumentException. A timeout set through this API could therefore
never be cleared, and getTimeout() kept reporting the stale value.

A null timeout now restores the timeout the query inherits from its entity
manager, which is what the query would have used had setTimeout() never
been called. Deliberately not the value of the configuration, which would
discard an entity manager scoped timeout the caller never set here.

getTimeout() reports the effective fetch plan value rather than the
recorded hint, so it cannot disagree with what the query will actually
use, and StoredProcedureQueryImpl delegates both methods to its query so
the two cannot drift apart.

EntityManagerImpl carries a setTimeout/getTimeout pair too, but those
implement EntityTransaction, a transaction timeout in seconds, and are left
alone here.
@rzo1 rzo1 self-assigned this Aug 29, 2026
@rzo1
rzo1 requested review from cristof and solomax August 29, 2026 18:16
Comment thread openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java Outdated
Comment thread openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java Outdated
Review feedback: getTimeout() derived null from the effective value being
non positive, so an explicit setTimeout(0) read back as null while a query
that merely inherited a timeout reported one. It now reports null when no
timeout is set on the query itself, and the effective value otherwise.

setTimeout(null) drops the recorded hint instead of re-recording the
inherited value, so a cleared timeout no longer shows up in getHints() and
no longer outranks a later openjpa.FetchPlan.QueryTimeout hint.

Also corrects the javadoc: a null timeout clears the timeout whatever set
it, not only one set through this method, and restores the value the entity
manager carries at that point rather than the one the query was created
with.
@rzo1
rzo1 requested a review from solomax August 31, 2026 19:26
@rzo1
rzo1 merged commit 360a9e8 into master Sep 2, 2026
4 checks passed
@rzo1
rzo1 deleted the OPENJPA-2986 branch September 2, 2026 17:14
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.

3 participants