GoogleCloudPlatform / spring-cloud-gcp

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

Spanner projection queries fail with interleaved properties #2129

Open meltsufin opened 1 year ago

meltsufin commented 1 year ago

Describe the bug When an entity has an @Interleaved property, it causes failures with projection queries that do not even have that property.

java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Parameter.getType()" because "paramMetadata" is null
    at com.google.cloud.spring.data.spanner.repository.query.SpannerStatementQueryExecutor.bindParameter(SpannerStatementQueryExecutor.java:460) ~[spring-cloud-gcp-data-spanner-4.5.1.jar:4.5.1]
    at com.google.cloud.spring.data.spanner.repository.query.SpannerStatementQueryExecutor.buildStatementFromSqlWithArgs(SpannerStatementQueryExecutor.java:441) ~[spring-cloud-gcp-data-spanner-4.5.1.jar:4.5.1]
    at com.google.cloud.spring.data.spanner.repository.query.SpannerStatementQueryExecutor.buildQuery(SpannerStatementQueryExecutor.java:357) ~[spring-cloud-gcp-data-spanner-4.5.1.jar:4.5.1]
    at com.google.cloud.spring.data.spanner.repository.query.SpannerStatementQueryExecutor.buildQuery(SpannerStatementQueryExecutor.java:300) ~[spring-cloud-gcp-data-spanner-4.5.1.jar:4.5.1]
...

Sample

https://github.com/Alos/SpannerCatProjectionIssue

Workaround

Use @Interleaved(lazy = true).

Alos commented 1 year ago

yeah I guess you need to do 2 things: 1. only go fetch the Interleaved data if its needed in the projection and 2. If you need to get the Interleaved data, always get the keys needed to get the information, even if not part of the parent query