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

Document restriction on embedded objects #784

Merged
merged 4 commits into from
Dec 10, 2021
Merged

Document restriction on embedded objects #784

merged 4 commits into from
Dec 10, 2021

Conversation

suztomo
Copy link
Contributor

@suztomo suztomo commented Dec 9, 2021

Related to #774


- embedded properties' column names must all be unique.
- embedded properties must be mutable; otherwise you'll get an error, such as `SpannerDataException: Column not found: parent`.
Therefore, you cannot use Kotlin's data class, which is immutable, to hold an embedded property.
Copy link
Contributor Author

@suztomo suztomo Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate. Kotlin's data class can have mutable field with 'var'. But the following definition (@Embedded var entityHistory) failed too with the same error message as #774 (comment):

@Table(name = "Requests")
data class Request(
    @PrimaryKey val requestId: String,
    val payload: String,
    @Embedded var entityHistory: EntityHistory? = null
)

What's the better description?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rephrase somehow that the constructor should not contain embedded properties?

It seems that to use Kotlin data class with @Embedded, we can do something like:

@Table(name = "Requests")
data class Request(
    @PrimaryKey val requestId: String,
    val payload: String,
) {
    @Embedded lateinit var entityHistory: EntityHistory
}

or

@Table(name = "Requests")
data class Request(
    @PrimaryKey val requestId: String,
    val payload: String,
) {
    @Embedded var entityHistory: EntityHistory? = null
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Embedded properties must not be passed through constructor"? This would apply to both Java and Kotlin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elefeint @gaeshi Thank you for feedback. Updated.

Copy link
Contributor Author

@suztomo suztomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elefeint PTAL. Feel free to edit/merge this PR.


- embedded properties' column names must all be unique.
- embedded properties must be mutable; otherwise you'll get an error, such as `SpannerDataException: Column not found: parent`.
Therefore, you cannot use Kotlin's data class, which is immutable, to hold an embedded property.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elefeint @gaeshi Thank you for feedback. Updated.

@suztomo suztomo requested a review from elefeint December 10, 2021 20:10
docs/src/main/asciidoc/spanner.adoc Outdated Show resolved Hide resolved
@suztomo suztomo changed the title restriction on embedded objects Document restriction on embedded objects Dec 10, 2021
Co-authored-by: Elena Felder <41136058+elefeint@users.noreply.github.com>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@suztomo suztomo merged commit bc71f8f into GoogleCloudPlatform:main Dec 10, 2021
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
* restriction on embedded objects

* Enhanced restriction on embedded properties

* Update docs/src/main/asciidoc/spanner.adoc

Co-authored-by: Elena Felder <41136058+elefeint@users.noreply.github.com>

Co-authored-by: Elena Felder <41136058+elefeint@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants