Pagination & Sorting — Concept Check
Questions on Pagination & Sorting. Pass a Pageable object to repository methods; Spring Data returns a Page<T> containing the slice of results plus total-count metadata.
Questions in this quiz
8 questions on Pagination & Sorting — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer uses Page<T> for a REST API with large data sets and notices performance issues. What could be the cause?
- APage<T> does not support pagination.
- BThe Pageable object is incorrectly configured.
- CPage<T> always fetches all records.
- DThe COUNT(*) query is expensive for large tables.
2.In a Spring Data JPA application, what happens if you pass unsanitized user input directly to Sort?
- AIt may lead to SQL injection vulnerabilities.
- BThe sort operation will be ignored.
- CThe application will automatically sanitize the input.
- DThe database will crash due to invalid queries.
3.A service uses Slice<T> for infinite scroll. What is a key advantage of this approach?
- AIt provides total element count for pagination.
- BIt skips the COUNT(*) query, improving performance.
- CIt automatically handles sorting of records.
- DIt supports multiple sort fields by default.
4.A developer wants to sort orders by 'createdAt' and 'status'. How can this be achieved in Spring Data JPA?
- AUse Pageable without Sort.
- BUse PageRequest.of with Sort.by multiple fields.
- CSort fields cannot be combined in Spring Data JPA.
- DUse Slice<T> to handle multiple fields.
5.What is a potential issue when setting a large page size in Pageable?
- AIt disables sorting on the results.
- BIt causes the application to crash.
- CIt automatically reduces the number of pages.
- DIt may lead to high memory usage and slow response times.
6.A developer uses @PageableDefault in a controller. What does this achieve?
- AAutomatically sorts results by primary key.
- BSets default pagination parameters when none are provided.
- CLimits the number of results to a fixed value.
- DDisables pagination for the controller method.
7.Why might a developer choose Slice<T> over Page<T> for a mobile app's infinite scroll feature?
- ASlice<T> automatically handles sorting.
- BSlice<T> provides total pages information.
- CSlice<T> does not perform a COUNT query, improving performance.
- DSlice<T> supports complex queries by default.
8.In Spring Data JPA, what is the role of the Pageable object?
- AIt specifies pagination and sorting instructions for queries.
- BIt handles database connections and transactions.
- CIt automatically maps database rows to entities.
- DIt provides security features for data access.