Affects: \Spring Boot 2.1.3


I'm getting an error with some JPQL queries which include the '%' characters (single quotes included). The problem seems to be, that the parser believes the named parameter is quoted out, even though it is not. The problem is somehow related with the number of characters, since when I change variable names or number of parameters the error comes and goes.

org.springframework.dao.InvalidDataAccessResourceUsageException: Named parameter not bound : __$synthetic$__19; nested exception is org.hibernate.QueryException: Named parameter not bound : __$synthetic$__19

I've created an example project which demonstrates this error: https://github.com/kancsuki/spring-parser-error-example

Note: I found that the following things could be related, but did not go any deeper. - org.springframework.data.repository.query.SpelQueryContext.SpelExtractor#quotations - org.springframework.data.jpa.repository.query.StringQuery.ParameterBindingParser#parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery

Comment From: mfedirko

In parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery, the matcher is referencing the parsed query.

Matcher matcher = PARAMETER_BINDING_PATTERN.matcher(resultingQuery);

When checking for quotes in the matched parameters, the matcher passes its own indexes from the parsed query to the spelExtractor.isQuoted method which references the original non-parsed query.

            if (spelExtractor.isQuoted(matcher.start())) {
                continue;
            }

By coincidence it appears the start index of some of your parameters in the parsed query match the start index of quotes in the original query.

quoteranges

Thus, the above lines skip binding the parameters which results in the named parameter not bound exception.

I was able to get your test to pass by changing the names of some parameters in the filter slightly.

testpassedspringparser .

Comment From: mfedirko

Updated query below.

updatedquery

Comment From: odrotbohm

Would you please create a ticket in the Spring Data bug tracker for that. Also, be reminded that we're not accepting contributions that just contain production code changes. They need to be accompanied by test cases as indicated in the check list in the PR.

Comment From: peter891014

问题已解决,很nice

Comment From: felixng1028

https://jira.spring.io/browse/DATAJPA-1683