Skip to content

Parameter bind marker in query comments are not ignored by ParameterBindingParser #4090

Open

Description

@hosamaly

In the following code, the query has a question mark inside a comment, but this is causing a validation exception to be thrown.

interface MyRepository extends JpaRepository {
    @Query("""
           select *
             from MyEntity /* TODO: should I use YourEntity? */
            where id = :id
           """)
    Optional<MyEntity> findMyEntity(Long id);
}
Caused by: java.lang.IllegalArgumentException: Mixing of ? parameters and other forms like ?1 is not supported
	at org.springframework.data.jpa.repository.query.StringQuery$ParameterBindingParser.parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(StringQuery.java:286) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.StringQuery.<init>(StringQuery.java:85) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.DeclaredQuery.of(DeclaredQuery.java:40) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.JpaQueryMethod.assertParameterNamesInAnnotatedQuery(JpaQueryMethod.java:168) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:149) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.DefaultJpaQueryMethodFactory.build(DefaultJpaQueryMethodFactory.java:44) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94) ~[spring-data-jpa-3.3.11.jar:3.3.11]
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:115) ~[spring-data-commons-3.3.11.jar:3.3.11]

The validation should occur after the comments are stripped out.

Activity

  1. mp911de commented on Nov 20, 2025

    @mp911de
    Member

    Parameter pre-processing does not consider comments at all, block comments (/* … */, single-line comments (// …) or SQL-style (-- …) comments.

    Ignoring comments requires covering the entire syntax space including quotations. That is a hard problem to solve. We would have to ignore comments with proper consideration of the grammar so that statements like WHERE id = '// ?' and foo = :bar and baz = ? or WHERE id = '/*' and foo = :bar and baz = ? and bar = '*/' match properly and the contents between e.g. /* and */ is not ignored (that is ignoring comment markers within literals and detect quotation bounds).

    While your case is rather uncommon and causes clearly inconvenience, the complexity behind this issue is rather involved and so we leave things as they are for the time being.

    Please also note that Spring Data JPA 3.3 is no longer supported, please refer to https://spring.io/projects/spring-data-jpa#support for maintained versions.

  2. changed the title [-]Question marks in query comments cause a validation error[/-] [+]Parameter bind marker in query comments are not ignored by `ParameterBindingParser`[/+] on Nov 20, 2025
  3. added 4 commits that reference this issue on Jan 14, 2026
    97fa697
    6f41de5
    fd15221
    55fafc9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions