-
Notifications
You must be signed in to change notification settings - Fork 1.5k
count query with expressions requires the same number of expressions as select query for parameter binding to succeed #2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can't reproduce this. I wrote a test case... // GH-2475
@Query(value = "SELECT * FROM SD_User u WHERE u.firstname = :#{#firstname} and u.lastname = :#{#lastname}",
countQuery = "SELECT COUNT(*) FROM SD_User u WHERE u.firstname=:#{#firstname}", nativeQuery = true)
Page<User> search(String firstname, String lastname, Pageable pageable); @Test // GH-2475
void countQueriesShouldOnlyBindParametersFoundInTheQuery() {
flushTestUsers();
Page<User> pageOfUsers = repository.search("Dave", "Matthews", PageRequest.of(0, 1));
assertThat(pageOfUsers.getContent()).containsExactlyInAnyOrder(thirdUser);
} It passes green. This clearly has two parameters fed to the primary query and one in the count query. It also have Additionally, I dug in with the debugger, and it seems to have the proper bindings for each query. See attached screen shots. Thus, I'm not convinced that this issue exists. Perhaps it existed before, but was side effect of some other issue recently resolved. Or if this isn't an issue on |
Hi @gregturn could you test by making the count query have 3 parameters or using lastname parameter in the count query instead of first name parameter |
Okay, something blew up with this: @Query(value = "SELECT * FROM SD_User u WHERE u.firstname = :#{#firstname}",
countQuery = "SELECT COUNT(*) FROM SD_User u WHERE u.firstname = :#{#firstname} and u.lastname = :#{#lastname}", nativeQuery = true)
Page<User> search(String firstname, String lastname, Pageable pageable); and @Test // GH-2475
void countQueriesShouldOnlyBindParametersFoundInTheQuery() {
flushTestUsers();
Page<User> pageOfUsers = repository.search("Dave", "Matthews", PageRequest.of(0, 1));
assertThat(pageOfUsers.getContent()).containsExactlyInAnyOrder(thirdUser);
} with a stack trace like this:
|
Seems related: #2140 |
#2140 involves a JPQL grammar error to handle This ticket is the side effect of reusing bindings between the I'm actually more interested in https://github.com/spring-projects/spring-data-jpa/commits/issue/3041, because this directly interacts with the same bits. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
the count query uses parameter binding of the query so for the count query to be generated correctly it has to use the same expressions as the original query in the same order.
for example, the below query annotation
does not work because countQuery does not use same number of parameters as the select query
however this one works
I think countQuery should not share parameterBindings of original select query
The text was updated successfully, but these errors were encountered: