Support dynamic SQL provider for @Query methods - #2333
Open
benelog wants to merge 1 commit into
Open
Conversation
Introduce the QueryProvider SPI generating the SQL statement to execute at runtime, based on the bound parameter values. A provider implementation can be configured via @query(queryProviderClass = …) while parameter binding, query execution, and result mapping remain handled by Spring Data JDBC. Query methods using a QueryProvider are excluded from AOT repository generation and resolve at runtime. Closes spring-projects#542 Signed-off-by: Sanghyuk Jung <sanghyuk.jung@navercorp.com>
benelog
force-pushed
the
gh-542-dynamic-sql-provider
branch
from
July 25, 2026 14:49
9517582 to
7c93ef2
Compare
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.
Introduce a
QueryProviderSPI that generates the SQL statement for a repository query method at runtime, based on the bound parameter values, following the design discussed in #542. A provider implementation is configured via the newqueryProviderClassattribute of@Query, while parameter binding, query execution, and result mapping remain handled by Spring Data JDBC:Changes:
QueryProviderfunctional interface (getQuery(SqlParameterSource)plusisNotNull/isNotEmptydefault helpers) inorg.springframework.data.jdbc.repository.query.@Query(queryProviderClass = …)attribute, mutually exclusive withvalueandname. The configured class gets instantiated through its default constructor, following therowMapperClassconventions.StringBasedJdbcQueryobtains the SQL statement from the provider on every invocation after parameter binding. CustomRowMapper/ResultSetExtractorconfiguration applies as for any other@Querymethod. Value expressions and#{#tableName}preprocessing are not applied to provider-generated SQL.DeclaredQueryLookupStrategyresolves provider methods first and reports invalid combinations (value/nametogether with a provider, non-instantiable provider classes) withIllegalArgumentExceptionso thatCREATE_IF_NOT_FOUNDdoes not silently fall back to query derivation.QueryProviderare excluded from AOT repository generation and resolve at runtime.Closes #542