Skip to content

DATAJPA-1544 - Delete totals.size() == 1 condition in count method #388

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

Closed
wants to merge 4 commits into from

Conversation

JIANGc
Copy link

@JIANGc JIANGc commented Jul 1, 2019

The totals.get(0) cannot always get the correct count result no matter
whether there is a group by clause or not. There is also
misunderstanding when we use getTotalElements method for paging.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

class JpaQueryExecution.

The totals.get(0) cannot always get the correct count result no matter
whether there is a group by clause or not. There is also
misunderstanding when we use getTotalElements method for paging.
@schauder
Copy link
Contributor

schauder commented Jul 2, 2019

This change causes a couple of test failures in UserRepositoryFinderTests UserRepositoryTests and tests derived from that.

@JIANGc can you take a look if this can be saved?

@JIANGc
Copy link
Author

JIANGc commented Jul 11, 2019

Thanks @schauder . I made some updates and fixed unit tests.

@@ -204,13 +210,33 @@ protected Object doExecute(final AbstractJpaQuery repositoryQuery, final Object[
}

private long count(AbstractJpaQuery repositoryQuery, Object[] values) {

StringBuilder builder = new StringBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't really grasp what is going on here.

I guess it starts with the previously existing version of the source code, which is bogus AFAIK since a count query must always return exactly one value.
Therefore this PR should be done on top of #400.

Any parsing of queries should happen where all the other parsing happens inside AstractJpaQuery derivatives.

And finally and possibly most crucial: The problem is that the generation of the count query is broken so that is the location that should get fixed.

@gregturn
Copy link
Contributor

gregturn commented May 5, 2022

As stated, this needs to be redone, on top of #400. I think starting from there with a fresh PR, will do much better.

@gregturn gregturn closed this May 5, 2022
@gregturn gregturn removed the status: waiting-for-triage An issue we've not yet triaged label May 5, 2022
@gregturn gregturn self-assigned this May 5, 2022
@gregturn gregturn added the status: declined A suggestion or change that we don't feel we should currently apply label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants