You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.On native queries part, it is not clear what dynamic sorting means in this context (passing a Sort, Pageable)?
2.The following paragraph it says that Pageable is supported, I think it is not clear whether it applies to the Sort part in it?
3.Then it says the countQuery is needed, but Ive seen examples with native queries and countQuery not being needed, so I guess there must be some counterpart.
4. Besides, non-native @queries are not mentioned, does that mean that countQuery is completely useless on those? How does JPA perform the magic counting? By issuing the whole query and counting the results? Or by rewriting it as SELECT count(*) internally? If its the former, I believe there should be a note stating that even JPA can infer the totals, it's always advised to provide the query yourself for performance
Thanks guys! Your project is amazing
The text was updated successfully, but these errors were encountered:
Spring Data JPA does not currently support dynamic sorting for native queries, because it would have to manipulate the actual query declared, which it cannot do reliably for native SQL.
is intentionally vague as rewriting queries for sorting works only for simple cases. More complex queries (with fancy aliases, subqueries, join, unions) can work but that's not guaranteed. Since Pageable contains a Sort as well, it's obvious that when talking about sorting and you see Pageable, the context applies.
Similar goes for count queries. We can derive these in a lot of cases, but not all.
How does JPA perform the magic counting?
JPA implementations have a JPQL parser and they extract what's necessary. We don't have it (yet).
I'd like to keep this ticket open until we implement #2846. Once that is in place, we can refine our query parsing capabilities.
Spring Data can rewrite simple queries for pagination and sorting. More complex queries require either JSqlParser to be on the class path or a countQuery declared in your code. See the example below for more details.
By reading https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query.native, I realised there are few important aspects that I think it would be interesting to extend:
1.On native queries part, it is not clear what dynamic sorting means in this context (passing a Sort, Pageable)?
2.The following paragraph it says that Pageable is supported, I think it is not clear whether it applies to the Sort part in it?
3.Then it says the countQuery is needed, but Ive seen examples with native queries and countQuery not being needed, so I guess there must be some counterpart.
4. Besides, non-native @queries are not mentioned, does that mean that countQuery is completely useless on those? How does JPA perform the magic counting? By issuing the whole query and counting the results? Or by rewriting it as SELECT count(*) internally? If its the former, I believe there should be a note stating that even JPA can infer the totals, it's always advised to provide the query yourself for performance
Thanks guys! Your project is amazing
The text was updated successfully, but these errors were encountered: