Skip to content

Allow overriding the SQL dialect used to validate native @Query statements #1975

Description

@w8854123

Expected Behavior

For native Spring Data @Query statements, Spring Tools should select the SQL parser/validator from the actual database dependency or provide an explicit way to choose the dialect. A project using PostgreSQL should validate and highlight PostgreSQL-specific syntax such as CAST(:managementIp AS inet) correctly.

Current Behavior

Native queries are parsed as MySQL when a MySQL/MariaDB JDBC driver is present on the classpath, even if the query targets PostgreSQL. The current dependency-based selection prioritizes MySQL/MariaDB over PostgreSQL, and there is no per-project, datasource, repository, or query-level setting to override the selected dialect.

For example:

@Query(value = "SELECT * FROM machine WHERE management_ip = CAST(:managementIp AS inet)", nativeQuery = true)

is valid PostgreSQL SQL, but inet is reported incorrectly when the query is parsed using the MySQL grammar.

Context

Projects can legitimately include more than one JDBC driver—for example, because of migration tooling, tests, integrations, or multiple datasources. In that situation, classpath inference alone is ambiguous and its current MySQL-first precedence causes false syntax diagnostics for PostgreSQL native queries.

Please add an explicit SQL dialect configuration/override, ideally supporting project or datasource scope and, if feasible, individual native @Query declarations. This would complement the classpath inference introduced by #1273 and prevent valid vendor-specific SQL from being validated against the wrong grammar.

Related: #1273 and #1236.

Activity

  1. added
    for: eclipse
    for: vscode
    and removed on Aug 26, 2026
  2. BoykoAlex commented on Sep 22, 2026

    @BoykoAlex
    Contributor

    I was thinking of having a setting/preference that would allow to select the SQL dialect per project. However, VSCode seems to allow settings per workspace folder rather than project in the workspace folder. Therefore for a multi-module project where different modules use different SQL dialects it won't work flawlessly... Hypothetically that would fine in Eclipse but there is no lsp integration for project preferences i think (we had to engineer our own lsp config <-> eclipse prefs integration).
    All of this seems a bit challenging without a clear win... But we could fix it for folks to experiment... it would allow some flexibility for the users with respect to SQL dialect overriding.
    (@martinlippert @w8854123 ^^)

  3. w8854123 commented on Sep 23, 2026

    @w8854123
    Author

    I was thinking of having a setting/preference that would allow to select the SQL dialect per project. However, VSCode seems to allow settings per workspace folder rather than project in the workspace folder. Therefore for a multi-module project where different modules use different SQL dialects it won't work flawlessly... Hypothetically that would fine in Eclipse but there is no lsp integration for project preferences i think (we had to engineer our own lsp config <-> eclipse prefs integration). All of this seems a bit challenging without a clear win... But we could fix it for folks to experiment... it would allow some flexibility for the users with respect to SQL dialect overriding. (@martinlippert @w8854123 ^^)

    Thank you for taking the time to investigate this and for replying.

    I should mention that I am only a regular Spring Tools user and have not looked at the source code myself. The suggestions I made were based on an AI-assisted analysis, so they may not be technically accurate or fully feasible.

    From a user's perspective, one possible approach might be to provide a workspace-level SQL dialect setting, while keeping the existing classpath-based detection as the default. If feasible, a project-local configuration file that is independent of a particular editor could also help with multi-module projects where different modules use different dialects.

    However, I understand that supporting this consistently across VS Code, Eclipse, and the language server may be more complicated than it initially appears. These are only tentative suggestions from a user perspective, and I will leave the design and feasibility assessment to you.

    Thanks again for your consideration and for your work on this issue.

  4. BoykoAlex commented on Sep 23, 2026

    @BoykoAlex
    Contributor

    I was thinking a bit in the direction of a config file per project as well... in this case we cannot take advantage of the config/preference UI on the IDE side but perhaps this is okay if we provide quickfixes via resource markers as this would be the UI to change the sql dialect... I just don't want to build "lsp integration" for the config file per project from scratch. Wonder i could re-use project index storage for this idea then @martinlippert...
    At the moment I'm implementing this via LSP configuration API and IDE settings/preferences. For VSCode it's going to be limited to workspace folder rather than a project...

  5. martinlippert commented on Sep 23, 2026

    @martinlippert
    Member

    I think a workspace-wide (or even installation-wide) preference for this should be fine. No need to have anything per-project, as this concept doesn't exist in VSCode or the LSP protocol - just a regular preference that users can edit via the usual mechanisms.

    We can allow users to switch between "auto-select" the SQL dialect (basically the mechanism that we use as of today, based on the drivers on the classpath) and a "manual config" mode.

    The underlying issue here is that we can have multiple drivers and dialects even within the same project, so a project-side setting to select the dialect would only help in certain situations (one dialect per project), but not in others (multiple dialects per project). Therefore, I am thinking about a preference that allows the validation to pick the right dialect for an individual repository. For this to work, we might need a preference that allows users to, for example, set a dialect for a specific package prefix. That way, we could identify the correct dialect when running the validation by checking for the dialect setting for the current package. This validation could then also report if there is no match found, etc. As soon as we have this, a workspace-wide preference would be enough I think.

    The "auto-select" mode could be enhanced with a validation that checks the classpath for multiple drivers to be around and report that situation to the user, so that users are made aware of the situation where multiple drivers are on the classpath and the auto-select mode might select the wrong one.

  6. added this to the 5.5.0.RELEASE milestone on Sep 25, 2026
  7. BoykoAlex commented on Sep 25, 2026

    @BoykoAlex
    Contributor

    Not quite what @martinlippert meant so re-opening to adjust the solution

  8. marked SQL syntax validation #1273 as a duplicate of this issue on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: eclipsefor: vscodetheme: spring-data-supporttheme: validationtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions