[OPENJPA-2986] Let setTimeout(null) clear a query timeout - #169
Merged
Conversation
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.
cristof
approved these changes
Aug 29, 2026
solomax
reviewed
Aug 31, 2026
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.
solomax
approved these changes
Sep 2, 2026
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.
Query.setTimeout(null)passed the null straight tosetHint(), which drove it throughFetchConfigurationImpl.setHint()into a reflective call ofsetQueryTimeout(int)and failed with abad-hint-valueIllegalArgumentException. So a timeout set through this API could never be cleared — on queries it did not silently ignore the null, it threw — andgetTimeout()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 notFetchPlan.DEFAULT, which resolves to theOpenJPAConfigurationvalue 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, andStoredProcedureQueryImpldelegates both methods to its query so the two cannot drift apart.EntityManagerImplcarries asetTimeout/getTimeoutpair too, but those implementEntityTransaction— a transaction timeout in seconds — and are left alone here.