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

Spanner - PK fields which can be null - Save entity with @Interleaved field #2621

Open
agustintabarez opened this issue Feb 20, 2024 · 1 comment
Labels
priority: p2 type: bug Something isn't working

Comments

@agustintabarez
Copy link

agustintabarez commented Feb 20, 2024

Describe the bug
The error occurs when inserting an entity that has an interleaved relationship with another table, and at least one shared primary key is null.

Versions:
spring-cloud-gcp-dependencies: 5.0.3
spring-boot: 3.2.2

Sample

@Table
public class Parent { 

  @PrimaryKey
  @Column
  private String keyOne;

  @PrimaryKey(keyOrder = 2)
  @Column
  private Long keyTwo;

  @Interleaved
  private List<Child> children;

  // More fields
}

@Table
public class Child { 

  @PrimaryKey
  @Column
  private String keyOne;

  @PrimaryKey(keyOrder = 2)
  @Column
  private Long keyTwo;

  @PrimaryKey(keyOrder = 3)
  @Column
  private Long keyThree;

  // More fields
}

var keyOne = "keyOne";
var keyTwo = null;
var keyThree = "keyThree";
List<Child> children = List.of(new Child(keyOne, keyTwo, keyThree));

Parent parent = new Parent(keyOne, keyTwo, children);
parentRepository.save(parent) // extends SpannerRepository

Error:

Cannot invoke "Object.equals(Object)" because the return value of "java.util.Iterator.next()" is null

Screenshot 2024-02-20 at 14 10 25

@agustintabarez agustintabarez changed the title Spanner - PK fields which can be null - Save entity with @Interleaved field - NPE Spanner - PK fields which can be null - Save entity with @Interleaved field Feb 20, 2024
@agustintabarez
Copy link
Author

agustintabarez commented Feb 20, 2024

Following the same example, also an error occurs when retrieving an entity that has some PK field null.

  1. Find All
    parentRepository.findAll(); // parentRepository extends SpannerRepository<Parent, Object[]>

It only throws error when using @Interleaved(lazy = true).

  1. Find By ID
Object[] keys = new Object[2];
keys[0] = "not-null-key";
keys[1] = null; // Also tried not to send this key
this.parentRepository.findById(keys);

Screenshot 2024-02-20 at 15 14 17

@mpeddada1 mpeddada1 added type: bug Something isn't working priority: p2 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants