Skip to content

Pagination not working #337

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

Closed
rezaep opened this issue Apr 8, 2020 · 2 comments
Closed

Pagination not working #337

rezaep opened this issue Apr 8, 2020 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@rezaep
Copy link

rezaep commented Apr 8, 2020

It's my first experience with spring-data-r2dbc, so I'm not sure if it's a bug or I'm missing something.

Description

I'm using spring-data-r2dbc with Kotlin and WebFlux.

build.gradle.kts:

plugins {
    id("org.springframework.boot") version "2.3.0.M4"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    kotlin("jvm") version "1.3.71"
    kotlin("plugin.spring") version "1.3.71"
}
...
dependencies {
    implementation("org.springframework.boot:spring-boot-starter-cache")
    implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springframework.boot:spring-boot-starter-validation")
...
}

Assuming I have a simple Repository:

CityRepository:

interface CityRepository : ReactiveCrudRepository<City, Long> {
    fun findByNameContainingIgnoreCase(name: String, page: Pageable): Flux<City>
}

When I call the findByNameContainingIgnoreCase with the following parameters:

val page = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "name"))
return cityRepository.findByNameContainingIgnoreCase(name, page)
                .map { convertToModel(it) }

the generated log is:

2020-04-08 12:02:17.777 DEBUG 9184 --- [ctor-http-nio-2] o.s.d.r2dbc.core.DefaultDatabaseClient   : Executing SQL statement [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC]
2020-04-08 12:02:17.778 DEBUG 9184 --- [ctor-http-nio-2] o.s.d.r2dbc.core.NamedParameterExpander  : Expanding SQL statement [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC] to [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC]

According to the log, we can see only the sort is used and the query returns all rows matched to the where clause ordered by name.

But when I change the method in the repository to findTop10ByNameContainingIgnoreCase the log changes to:

2020-04-08 12:07:32.121 DEBUG 13020 --- [ctor-http-nio-2] o.s.d.r2dbc.core.DefaultDatabaseClient   : Executing SQL statement [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC LIMIT 10]
2020-04-08 12:07:32.121 DEBUG 13020 --- [ctor-http-nio-2] o.s.d.r2dbc.core.NamedParameterExpander  : Expanding SQL statement [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC LIMIT 10] to [SELECT city.city_id, city.name, city.state, city.country, city.lat, city.lng FROM city WHERE UPPER(city.name) LIKE UPPER($1) ORDER BY name ASC LIMIT 10]

which adds the limit to the query.

So, why passing Pageable to the query doesn't work for me? Am I missing something?

@mp911de mp911de added the status: duplicate A duplicate of another issue label Apr 8, 2020
@mp911de
Copy link
Member

mp911de commented Apr 8, 2020

This is a duplicate of #335.

@mp911de mp911de closed this as completed Apr 8, 2020
@vladimirshin
Copy link

What's the status on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants