-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
PanacheQuery count method ignoring distinct after using project #38033
Comments
/cc @FroMage (panache), @loicmathieu (panache) |
Issue is in return new CommonPanacheQueryImpl<>(this, newQuery.toString(), "select count(*) " + from); Should not have boolean distinctQuery = selectClause.toLowerCase().startsWith("distinct ");
if (distinctQuery) {
// 9 is the length of "distinct "
selectClause = selectClause.substring(9).trim();
newQuery.append("distinct ");
}
newQuery.append("new ").append(type.getName()).append("(").append(selectClause).append(")").append(from); |
Hello, I can have a look if no one is currently on this. |
Hello again @TigasArreis, I have opened a PR here : #38316 There are some errors in the build, I'll have a look at them btw. |
Hello @rysurd |
Thanks for testing!! I'll try to finish up the PR this week so it can be merged. |
Describe the bug
I have a query that uses distinct on the select
select distinct entity.id from Entity entity...
I want to use this query in a EntityRepository from where I want to return a
PanacheQuery<Long>
instead of aPanacheQuery<Entity>
When doing the following code:
This will return a correct count value because it generates the following queries:
However when applying .project (so I can have a
PanacheQuery<Long>
and not use unchecked raw types)It will remove the distinct from the count
And not returning the same .count() value
Expected behavior
After applying
.project()
to a generic PanacheQuery the.count()
value should remain the same after the projectionActual behavior
The
.count()
value changes because the distinct from the select clause is being removed after applying.project()
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
17.0.7
Quarkus version or git rev
3.2.2.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
As a workarround it's possible to create a
EntityIdRepository implements PanacheRepository<Long>
to avoid the unchecked raw typesThe text was updated successfully, but these errors were encountered: