Skip to content

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

@hosamaly

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions