-
Notifications
You must be signed in to change notification settings - Fork 30
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
[clarification]: should PageRequest<?> really be allowed #603
Comments
It would make sense to add language to the spec that the user must not mix incompatible type parameters, which would allow implementations to validly reject it. However, it would need to be done very precisely because there are cases where an implementation might have a valid use for that example as an extension to the spec. For example, if
Disallowing the above wouldn't be consistent with the previous compromise that allowed us to add type parameters to the spec. An implementation would be free to issue a warning for this usage without any spec language. Would that be good enough? |
In JDQL we have the notion of a unique "queried entity", so this doesn't arise. In full JPQL, all this is much more complicated since the cursor might need to include fields of multiple entities referred to from the
The spec can say what vendors must support, without restricting what vendors may support as an extension. This is the approach we have always taken in the JPA spec.
I figured you might say that. But as I tried to point out above,
That might be OK, but I would much prefer to make it an error. It's not that it's hard for me to implement; I've already implemented it. But in the implementation I had to use a cast to a raw type, which is your red flag that this is something that's unsound. I would sorta prefer that we not bake in things that are unsound as required features. |
So a more radical idea would be to revisit the whole idea of hanging History (from my perspective)When I had originally modeled this in my head, a Well, except, it doesn't actually work. a But anyway, continuing along, when I saw that In summaryBut now I'm wondering whether this was all a big mistake, and an unnecessary one.
ProposalSo, I think we should discuss simplifying
And, to partially compensate for this loss, we could add We would then be able to simplify The question raised by this issue would be resolved by side-effect, since On the TCK and implementation side, there would now be fewer things to implement, and fewer things to test. I understand it's late to be making API changes, but it seems to me that if a simplification like this really makes sense—and we're all comfortable with it—then not doing it would just be saddling ourselves with unnecessary technical debt. |
That's actually how I originally wrote it - with the Sorts decoupled from the page request. The decision was reversed and the coupling added back in #37 where I was outnumbered in the voting. |
OK. Well, I would say that it wasn't a bad idea to add But now we have more experience actually programming with the APIs, and actual solid implementations of these things, I guess we are better-placed than you guys were back in 2022. |
Actually, I think that in #618, @otaviojava is right that currently the rules surrounding Actually the true culprit is @Query("from Book order by title")
Page<Book> allBooks(PageRequest page); and reject this: @Query("from Book order by title")
Page<Book> allBooks(PageRequest page, Order<Book> order); at build time (or at startup). And everything would be hunky-dory. But since a
So I'm increasingly convinced that |
I have the same feeling. We currently have Jakarta Data Query Language, Order annotation, etc., which we did not have at that time. |
Now, we have thousands of ways to represent the sort in the query. I like the single responsibility principle, I mean, the pagination request handle with pagination. |
We have made the proposed change. Closing. |
Specification
PageRequest
,Order
,Sort
I need clarification on ...
whether we should really be accepting parameters of type
PageRequest<?>
,Sort<?>
, andOrder<?>
.Additional information
Strictly-speaking, the correct type for a parameter of type
PageRequest
isPageRequest<? super E>
orPageRequest<E>
whereE
is the queried entity type.However, in section 4.7 we don't specify any restrictions at all on the type arguments in
Sort
,Order
, orPageRequest
, and we have a couple of examples in the spec and javadoc wherePageRequest<?>
is used as the type of a repository method parameter. Worse, the TCK actually tests it.The problem with this is it limits the ability of compile-time tooling to provide feedback on method signatures of repository methods. I would like to be able to reject nonsensical things like:
But the spec doesn't really give me permission to do that.
I would even much prefer to reject:
(Note that this does not prevent the method being called via the untypesafe string-based mode, since
PageRequest.ofSize(40).sortBy(Sort.desc("name"), Sort.asc("id"))
is actually assignable toPageRequest<? super Author>
, which is strictly-speaking wrong in itself but it's a kind of wrong I guess I can live with.)Whatever, I think it's important that 4.7 be explicit about what is allowed and what can be rejected by the provider.
The text was updated successfully, but these errors were encountered: