Skip to content

getCountQuery is not configurable for use with DISTINCT #2509

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
maddin79 opened this issue Apr 27, 2022 · 3 comments
Closed

getCountQuery is not configurable for use with DISTINCT #2509

maddin79 opened this issue Apr 27, 2022 · 3 comments
Assignees
Labels
status: waiting-for-feedback We need additional information before we can continue

Comments

@maddin79
Copy link

I need to do a distinct count with specification. The code in the SimpleJpaRepository for the getCountQuery method has a the following if:

if (query.isDistinct()) {
    query.select(builder.countDistinct(root));
} else {
    query.select(builder.count(root));
}

But before that if the distinct of the query is never set, so I assume it is always false. I also can not set the distinct in the specification for this query. Like this the if does not make any sense or do I miss something?

Thanks

Best
Martin

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 27, 2022
@schauder
Copy link
Contributor

schauder commented May 9, 2022

What keeps you from calling query.setDistinct(true) in the specifications toPredicate method?

It is not a feature I'm particular fond of because Specifications really should focus on the predicate, but it does exist.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels May 9, 2022
@gregturn
Copy link
Contributor

gregturn commented May 9, 2022

@maddin79 Can you recheck things give we just merged #1380 (8ea70c1) to main. This should parse the Distinct keyword found in custom count methods, and thus ONLY apply the distinct inside the select count(...) function (not outside).

See if this resolves this resolves the issue for you.

@gregturn gregturn self-assigned this May 9, 2022
@maddin79
Copy link
Author

maddin79 commented May 9, 2022

@schauder yes, you are right and in the meantime we found a different solution. We do not touch the query anymore in the specification itself.

@gregturn As I can see your solution fixed the problem. Good to know for the future, that there is a way now.

Thanks for your help and work :).

@maddin79 maddin79 closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

4 participants