Skip to content
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

KeysetScrollPosition.isInitial always returns false #3180

Closed
wsaca opened this issue Sep 30, 2023 · 2 comments
Closed

KeysetScrollPosition.isInitial always returns false #3180

wsaca opened this issue Sep 30, 2023 · 2 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@wsaca
Copy link

wsaca commented Sep 30, 2023

Hello, I have a problem trying to check if my query is in the first position:

Window<Role> findAllBy(ScrollPosition position);

When calling it, it returns 2 records:

Window<Role> window = roleRepository.findAllBy(ScrollPosition.keyset());

but window.positionAt(0).isInitial() always returns false

The reason apparently lies in the JpaMetamodelEntityInformation.getKeyset method which always returns at least one key set:

public Map<String, Object> getKeyset(Iterable<String> propertyPaths, T entity) {

getKeyset is used in ScrollDelegate.createWindow:

Map<String, Object> keys = entity.getKeyset(sort.stream().map(Order::getProperty).toList(), object);

and by calling window.positionAt(0).isInitial(), the KeysetScrollPosition.isInitial method checks the loaded keys where it always finds at least one and returns false:
https://github.com/spring-projects/spring-data-commons/blob/30dcacc8c1ef11d70580f7f79927122590a71ac7/src/main/java/org/springframework/data/domain/KeysetScrollPosition.java#L140

@quaff
Copy link
Contributor

quaff commented Oct 23, 2023

The javadoc of ScrollPosition.isInitial() states:

Returns whether the current scroll position is the initial one.

The javadoc of Window.positionAt() states:

Returns the {@link ScrollPosition} at {@code index}.

It doesn't state position at zero must be initial one, I don't think it's a bug.
Could you share your actual use case to check ScrollPosition.isInitial() ?

@mp911de mp911de assigned mp911de and unassigned gregturn Oct 23, 2023
@mp911de
Copy link
Member

mp911de commented Oct 23, 2023

What @quaff said. Conceptually, the initial position starts before index zero as it describes the position before the first element.

Regardless of keyset or offset mechanisms, if you request the next Window as of previous.positionAt(0) then the next window starts after the first element of the initial window of data.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
@mp911de mp911de added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants