spring-projects / spring-projects/spring-data-jpa

Remove bogus logic in count query [DATAJPA-1635]

Open
#1,937 2 comments 0 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Dec 30, 2020.

type: enhancement
Dominant language
Java
Stars
3.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Jens Schauder opened DATAJPA-1635 and commented

PagedExecution.count contains the following logic:

			List<?> totals = repositoryQuery.createCountQuery(accessor).getResultList();
			return (totals.size() == 1 ? CONVERSION_SERVICE.convert(totals.get(0), Long.class) : totals.size());

Which doesn't make sense since a count query should always only return a single result and if it doesn't just counting the results won't yield a meaningful result.

Turns out this exists only due to a bug in some unit tests that use the mocked original query for the count query


Referenced from: pull request https://github.com/spring-projects/spring-data-jpa/pull/400, and commits https://github.com/spring-projects/spring-data-jpa/commit/b9e9c6b0a1262f1a973383430cf9574d058efd92, https://github.com/spring-projects/spring-data-jpa/commit/4dea8eb25702c88e631c6c5b0846f1edab26d9a6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.