[go: up one dir, main page]

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 - Error while having the Interleaved table having only one primary key which is same as the parent table #1646

Open
rajakumare1 opened this issue Mar 8, 2023 · 5 comments
Labels

Comments

@rajakumare1
Copy link
rajakumare1 commented Mar 8, 2023

Describe the bug
com.google.cloud.spring.data.spanner.core.mapping.SpannerDataException: A child table (tablename) must contain the primary key columns of its parent (tablename) in the same order starting the first column with additional key columns after.

If you have Interleave table that has only the same primary key as the Parent and doesnt have any additional key, then getting this Exception

Note: I have business reason to logically have another table to store separate information from ParentTable

Sample

public class Parent {

    @PrimaryKey(keyOrder = 1)
    @Column(name = "ParentId", nullable = false)
    private String ParentId;

  @Column(name = "details", nullable = false)
private String details


    @Interleaved
    private List<ParentLogical> parentLogical;

}

public class ParentLogical {

    @PrimaryKey(keyOrder = 1)
    @Column(name = "ParentId", nullable = false)
    private String ParentId;

  @Column(name = "associatedlogicalName", nullable = false)
private String associatedlogicalName

}

@rajakumare1 rajakumare1 changed the title Error while having the Interleaved table having only one primary key which is same as the parent table Spanner - Error while having the Interleaved table having only one primary key which is same as the parent table Mar 8, 2023
@meltsufin
Copy link
Member

Does the Spanner database even allow this? I believe the child table needs a secondary key. Have you tried just adding @PrimaryKey(keyOrder = 2) for associatedlogicalName?

@meltsufin meltsufin added spanner priority: p3 type: question Further information is requested labels Mar 8, 2023
@rajakumare1
Copy link
Author

Yes it allows the users to create interleave without the 2nd key order . I am 100% sure since I have created it and that’s when I ran into the issue

@meltsufin
Copy link
Member

I guess we just don't support this edge case. Have you tried my suggestion in the previous comment?

@rajakumare1
Copy link
Author

If I recreate the table ParentLogical and make a primary key with both the columns in the table then it works.

But my use case is totally different. The secondary table is just a logical table created so that main table doesnt have too many columns.

If I have the same primary key in both table, it doesnt work. The Database supports it so I humbly think the Spring Data should support too.

@meltsufin
Copy link
Member

Understood, I'll leave this issue in as a feature request.

@meltsufin meltsufin added type: enhancement New feature or request and removed type: question Further information is requested labels Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants