Skip to content

Wrong calculation of total number of elements when using DISTINCT clause [DATAJPA-342] #750

Closed
@spring-projects-issues

Description

@spring-projects-issues

Alex opened DATAJPA-342 and commented

If I define a custom query of this type:

@Query("SELECT DISTINCT m.genre FROM Media m WHERE m.user = ?1 ORDER BY m.genre ASC")
Page<String> getJukeGenres(User user, Pageable pageable);

The resulting Page element has wrong Total Elements.
It seems like it gives the number of total records instead of the distinct ones.

I had to create another adhoc query just to have the correct count:

@Query("SELECT count(*) as num FROM Media m WHERE m.user = ?1 AND m.genre IS NOT NULL")
long countGenres(User user);

But this is tedious workaround that I would like to avoid


Affects: 1.3 GA

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions