GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
416 stars 307 forks source link

ClassCastException when using Slice<T> or Page<T> in SpannerRepository #600

Open timopick opened 3 years ago

timopick commented 3 years ago

Issue When using Slice or Page in the repository I get a ClassCastException.

java.lang.ClassCastException: class x.y.z.MyEntityClass cannot be cast to class org.springframework.data.domain.Page (x.y.z.MyEntityClass and org.springframework.data.domain.Page are in unnamed module of loader 'app')
    at jdk.proxy2/jdk.proxy2.$Proxy76.findByProcessingDateTimeLessThanEqual(Unknown Source)

Example:

public interface MyRepository extends SpannerRepository<MyEntityClass, byte[]> {
    Page<MyEntityClass> findAllByProcessingDateTimeLessThanEqual(final Timestamp processingDateLte, final Pageable pageable);
}

When I change it to List, I get a result without error.

Dependencies:

dependencyManagement {
    imports {
        mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:2.0.4"
    }
}

dependencies {
...
    implementation "com.google.cloud:spring-cloud-gcp-starter-data-spanner"
}
zhumin8 commented 3 years ago

Thanks for capturing this.

amrnarvar commented 2 years ago

Any ETA for this fix?

elefeint commented 2 years ago

@armandomiani You can control pagination by passing Pageable parameters to custom query methods, but Page or Slice return types are not supported (except in findAll() method, which does not suit your usecase). As you have found, List is the alternative.

We'll take this as a feature request.

Alos commented 1 year ago

I too have found this limitation:

https://github.com/Alos/SpringCloudGCPPageIssue