-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Panache - load page with join fetch #26308
Comments
/cc @FroMage, @loicmathieu |
I've ran into this same issue today calling |
@FroMage As far as I understand, this is clearly a Panache issue, caused by the way Panache implements public static String getCountQuery(String query) {
// try to generate a good count query from the existing query
Matcher selectMatcher = SELECT_PATTERN.matcher(query);
String countQuery;
if (selectMatcher.matches()) {
// this one cannot be null
String firstSelection = selectMatcher.group(1).trim();
if (firstSelection.toLowerCase().startsWith("distinct ")) {
// this one can be null
String secondSelection = selectMatcher.group(2);
// we can only count distinct single columns
if (secondSelection != null && !secondSelection.trim().isEmpty()) {
throw new PanacheQueryException("Count query not supported for select query: " + query);
}
countQuery = "SELECT COUNT(" + firstSelection + ") " + selectMatcher.group(3);
} else {
// it's not distinct, forget the column list
countQuery = "SELECT COUNT(*) " + selectMatcher.group(3);
}
} else if (FROM_PATTERN.matcher(query).matches()) {
countQuery = "SELECT COUNT(*) " + query;
} else {
throw new PanacheQueryException("Count query not supported for select query: " + query);
}
// remove the order by clause
String lcQuery = countQuery.toLowerCase();
int orderByIndex = lcQuery.lastIndexOf(" order by ");
if (orderByIndex != -1) {
countQuery = countQuery.substring(0, orderByIndex);
}
return countQuery;
} That method removes the "SELECT" part of the query, but doesn't remove the "FETCH" clauses from the query. A "FETCH" clause without a corresponding "SELECT" clause doesn't make sense, hence the failure. That's precisely what the exception is trying to explain:
|
What is the state of this? Pagination also works just for simple queries, as soon as you join one to many relation it returns too few rows. Is there a desire to have proper pagination implemented, by doing a |
Do you have any other example of join queries where it returns invalid count results? This would be useful for testing. I guess we'd need to start with better query parsing :( |
From looking at the queries doing something like
would return only first X rows even if I want first X users right? |
Any updates on this? We're currently using Quarkus |
I'm working on a fix |
We do this by turning to the ORM HQLParser for non-trivial queries, but only for them, because the parser is much more expensive than simple string manipulation, so we keep the fast/easy logic. Fixes quarkusio#26308
Describe the bug
Hi,
loading a page using panache works great.
Problem is when you try to fetch subcollection within a page loading like this :
Calling a request without the joins for the count query works.
Maybe we can make this a bit more friendly as join with pagination is a common case.
Expected behavior
You should be able to load a page with a fetch join.
Replacing lazy by EAGER works. (but I don't want to be eager on every request...)
Actual behavior
The error
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
17
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.9.2.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: