spring-data-jpa
spring-data-jpa copied to clipboard
Supports scrolling base on keyset without id
id shouldn't be added to sort if provided sort contains unique property. See GH-2996
Removing the primary key isn't going to work, as Keyset scrolling must enforce uniqueness. Just accepting Sort isn't sufficient. What we could do is verify whether a unique property is a part of Sort. If not, we fall back to the primary key.
Removing the primary key isn't going to work, as Keyset scrolling must enforce uniqueness. Just accepting
Sortisn't sufficient. What we could do is verify whether a unique property is a part ofSort. If not, we fall back to the primary key.
IMO, we should add a section in document to elaborate advantage and limitation, guide developers to make best decision, avoid making code more complex.
I agree that we should improve the documentation in Commons to explain the relationship of Sort to the query and how we amend the Sort object.
I mean it is the responsibility of developer to make sure keys combination unique if the document emphasize that.
Test improved to cover such cases:
- unsorted (implicit sorted by id
asc) - explicit sorted by id
ascanddesc - explicit sorted by seqNo
ascanddesc - explicit sorted by (id, seqNo)
ascanddesc
all cases are tested against FORWARD and BACKWARD
Please, let's keep pull requests focused instead of mixing concerns within a single pull request.
Please, let's keep pull requests focused instead of mixing concerns within a single pull request.
Sorry to disturb you, those changes are related and necessary to make the test pass.
We don't work towards making tests pass that combine various aspects but rather include coordinated changes. I applied the directional retention via #2999 already. Including unique sort arguments and checking for these requires a bit more changes than we have in this PR.
Towards the sort requirements, we want the calling code to specify sort properties without the requirement to include always properties to make rows unique. Making rows unique is primarily a concern of our keyset scrolling code. If calling code wants to specify sort properties to make the result unique, then we can do so in the course of this pull request.
KeysetScrollIntegrationTests is extracted to https://github.com/spring-projects/spring-data-jpa/pull/3030 after https://github.com/spring-projects/spring-data-jpa/issues/2999 resolved.
A viable proposal is adding a boolean property (eg. keysetQualified) to Sort, let developer hint that based on unique columns.
We could introduce a global property indicate that sort is unique ensured by developer.
Commit updated, I introduce method JpaEntityInformation.isKeysetQualified() and default implementation is check whether unique property present, then skip include id in keyset, please take a look @mp911de